Skip to content

Commit

Permalink
deploy: d3dba51
Browse files Browse the repository at this point in the history
  • Loading branch information
theroyakash committed Nov 30, 2023
1 parent e9856c9 commit e200abb
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 58 deletions.
2 changes: 1 addition & 1 deletion search/search_index.json

Large diffs are not rendered by default.

78 changes: 39 additions & 39 deletions sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,197 +2,197 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://algorithms.theroyakash.com/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/blind75/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/cses/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/freebies/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/io/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/2heaps/problems/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/LinkedLists/problems/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/LinkedLists/stl-usage/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/arrays/array-problems/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/arrays/arrays/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/arrays/sliding-window/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/arrays/subarray/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/dp/dp-on-strings/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/dp/knapsack/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/dp/mcm/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/dp/problems/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/dp/stock-dp/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/dp/unbounded-knapsack/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/graph/bfs-dfs/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/graph/dsu/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/graph/problems/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/graph/standard-problems/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/graph/usage/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/greedy/problems/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/hashing/problems/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/heaps/heap-pq/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/heaps/problems/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/implementation/problems/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/recursion/intro/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/recursion/problems/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/search-sort/bs-ans/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/search-sort/cses-editorial/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/search-sort/intro/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/search-sort/problems-codeforces/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/search-sort/problems/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/stacks/problems/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/stacks/usage/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/trees/implementation/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://algorithms.theroyakash.com/trees/problems/</loc>
<lastmod>2023-11-29</lastmod>
<lastmod>2023-11-30</lastmod>
<changefreq>daily</changefreq>
</url>
</urlset>
Binary file modified sitemap.xml.gz
Binary file not shown.
37 changes: 19 additions & 18 deletions trees/problems/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5444,25 +5444,26 @@ <h3 id="approach_8">Approach</h3>
<p>We should traverse the tree in-order, so the values encountered are in non descending order. Now we count until we reach kth smallest value. We record the kth smallest value in some variable and return.</p>
<h3 id="code_8">Code</h3>
<div class="highlight"><pre><span></span><code><a id="__codelineno-19-1" name="__codelineno-19-1" href="#__codelineno-19-1"></a><span class="k">class</span><span class="w"> </span><span class="nc">Solution</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-2" name="__codelineno-19-2" href="#__codelineno-19-2"></a><span class="k">private</span><span class="o">:</span>
<a id="__codelineno-19-3" name="__codelineno-19-3" href="#__codelineno-19-3"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">treeNodeCount</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span><span class="w"> </span><span class="c1">// starting index is 1</span>
<a id="__codelineno-19-4" name="__codelineno-19-4" href="#__codelineno-19-4"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">setValue</span><span class="p">;</span><span class="w"> </span><span class="c1">// should hold the kth smallest value</span>
<a id="__codelineno-19-5" name="__codelineno-19-5" href="#__codelineno-19-5"></a><span class="k">public</span><span class="o">:</span>
<a id="__codelineno-19-6" name="__codelineno-19-6" href="#__codelineno-19-6"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">kthSmallest</span><span class="p">(</span><span class="n">TreeNode</span><span class="o">*</span><span class="w"> </span><span class="n">root</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">k</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-7" name="__codelineno-19-7" href="#__codelineno-19-7"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">root</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-8" name="__codelineno-19-8" href="#__codelineno-19-8"></a><span class="w"> </span><span class="n">kthSmallest</span><span class="p">(</span><span class="n">root</span><span class="o">-&gt;</span><span class="n">left</span><span class="p">,</span><span class="w"> </span><span class="n">k</span><span class="p">);</span>
<a id="__codelineno-19-9" name="__codelineno-19-9" href="#__codelineno-19-9"></a>
<a id="__codelineno-19-10" name="__codelineno-19-10" href="#__codelineno-19-10"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">treeNodeCount</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">k</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-11" name="__codelineno-19-11" href="#__codelineno-19-11"></a><span class="w"> </span><span class="n">setValue</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">root</span><span class="o">-&gt;</span><span class="n">val</span><span class="p">;</span><span class="w"> </span><span class="c1">// set the kth smallest value</span>
<a id="__codelineno-19-12" name="__codelineno-19-12" href="#__codelineno-19-12"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-19-2" name="__codelineno-19-2" href="#__codelineno-19-2"></a><span class="k">public</span><span class="o">:</span>
<a id="__codelineno-19-3" name="__codelineno-19-3" href="#__codelineno-19-3"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">id</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span>
<a id="__codelineno-19-4" name="__codelineno-19-4" href="#__codelineno-19-4"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">value</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">-1</span><span class="p">;</span>
<a id="__codelineno-19-5" name="__codelineno-19-5" href="#__codelineno-19-5"></a>
<a id="__codelineno-19-6" name="__codelineno-19-6" href="#__codelineno-19-6"></a><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">f</span><span class="p">(</span><span class="n">TreeNode</span><span class="o">*</span><span class="w"> </span><span class="n">root</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">k</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-7" name="__codelineno-19-7" href="#__codelineno-19-7"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="k">not</span><span class="w"> </span><span class="n">root</span><span class="p">)</span><span class="w"> </span><span class="k">return</span><span class="p">;</span>
<a id="__codelineno-19-8" name="__codelineno-19-8" href="#__codelineno-19-8"></a><span class="w"> </span><span class="n">f</span><span class="p">(</span><span class="n">root</span><span class="o">-&gt;</span><span class="n">left</span><span class="p">,</span><span class="w"> </span><span class="n">k</span><span class="p">);</span>
<a id="__codelineno-19-9" name="__codelineno-19-9" href="#__codelineno-19-9"></a><span class="w"> </span><span class="k">if</span><span class="p">(</span><span class="n">id</span><span class="o">++</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">k</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-10" name="__codelineno-19-10" href="#__codelineno-19-10"></a><span class="w"> </span><span class="n">value</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">root</span><span class="o">-&gt;</span><span class="n">val</span><span class="p">;</span>
<a id="__codelineno-19-11" name="__codelineno-19-11" href="#__codelineno-19-11"></a><span class="w"> </span><span class="k">return</span><span class="p">;</span>
<a id="__codelineno-19-12" name="__codelineno-19-12" href="#__codelineno-19-12"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-19-13" name="__codelineno-19-13" href="#__codelineno-19-13"></a>
<a id="__codelineno-19-14" name="__codelineno-19-14" href="#__codelineno-19-14"></a><span class="w"> </span><span class="n">treeNodeCount</span><span class="o">++</span><span class="p">;</span>
<a id="__codelineno-19-15" name="__codelineno-19-15" href="#__codelineno-19-15"></a><span class="w"> </span><span class="n">kthSmallest</span><span class="p">(</span><span class="n">root</span><span class="o">-&gt;</span><span class="n">right</span><span class="p">,</span><span class="w"> </span><span class="n">k</span><span class="p">);</span>
<a id="__codelineno-19-16" name="__codelineno-19-16" href="#__codelineno-19-16"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-19-17" name="__codelineno-19-17" href="#__codelineno-19-17"></a>
<a id="__codelineno-19-18" name="__codelineno-19-18" href="#__codelineno-19-18"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">setValue</span><span class="p">;</span>
<a id="__codelineno-19-19" name="__codelineno-19-19" href="#__codelineno-19-19"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-19-20" name="__codelineno-19-20" href="#__codelineno-19-20"></a><span class="p">};</span>
<a id="__codelineno-19-14" name="__codelineno-19-14" href="#__codelineno-19-14"></a><span class="w"> </span><span class="n">f</span><span class="p">(</span><span class="n">root</span><span class="o">-&gt;</span><span class="n">right</span><span class="p">,</span><span class="w"> </span><span class="n">k</span><span class="p">);</span>
<a id="__codelineno-19-15" name="__codelineno-19-15" href="#__codelineno-19-15"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-19-16" name="__codelineno-19-16" href="#__codelineno-19-16"></a>
<a id="__codelineno-19-17" name="__codelineno-19-17" href="#__codelineno-19-17"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="nf">kthSmallest</span><span class="p">(</span><span class="n">TreeNode</span><span class="o">*</span><span class="w"> </span><span class="n">root</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">k</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-19-18" name="__codelineno-19-18" href="#__codelineno-19-18"></a><span class="w"> </span><span class="n">f</span><span class="p">(</span><span class="n">root</span><span class="p">,</span><span class="w"> </span><span class="n">k</span><span class="p">);</span>
<a id="__codelineno-19-19" name="__codelineno-19-19" href="#__codelineno-19-19"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">value</span><span class="p">;</span>
<a id="__codelineno-19-20" name="__codelineno-19-20" href="#__codelineno-19-20"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-19-21" name="__codelineno-19-21" href="#__codelineno-19-21"></a><span class="p">}</span>
</code></pre></div>
<h3 id="time-and-memory-complexity">Time and memory complexity</h3>
<ul>
Expand Down

0 comments on commit e200abb

Please sign in to comment.