Skip to content

Commit 1afd1c7

Browse files
committed
Create README - LeetHub
1 parent 0cd45c1 commit 1afd1c7

File tree

1 file changed

+38
-0
lines changed
  • 2583-kth-largest-sum-in-a-binary-tree

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<h2><a href="https://leetcode.com/problems/kth-largest-sum-in-a-binary-tree/">2583. Kth Largest Sum in a Binary Tree</a></h2><h3>Medium</h3><hr><div><p>You are given the <code>root</code> of a binary tree and a positive integer <code>k</code>.</p>
2+
3+
<p>The <strong>level sum</strong> in the tree is the sum of the values of the nodes that are on the <strong>same</strong> level.</p>
4+
5+
<p>Return<em> the </em><code>k<sup>th</sup></code><em> <strong>largest</strong> level sum in the tree (not necessarily distinct)</em>. If there are fewer than <code>k</code> levels in the tree, return <code>-1</code>.</p>
6+
7+
<p><strong>Note</strong> that two nodes are on the same level if they have the same distance from the root.</p>
8+
9+
<p>&nbsp;</p>
10+
<p><strong class="example">Example 1:</strong></p>
11+
<img alt="" src="https://assets.leetcode.com/uploads/2022/12/14/binaryytreeedrawio-2.png" style="width: 301px; height: 284px;">
12+
<pre><strong>Input:</strong> root = [5,8,9,2,1,3,7,4,6], k = 2
13+
<strong>Output:</strong> 13
14+
<strong>Explanation:</strong> The level sums are the following:
15+
- Level 1: 5.
16+
- Level 2: 8 + 9 = 17.
17+
- Level 3: 2 + 1 + 3 + 7 = 13.
18+
- Level 4: 4 + 6 = 10.
19+
The 2<sup>nd</sup> largest level sum is 13.
20+
</pre>
21+
22+
<p><strong class="example">Example 2:</strong></p>
23+
<img alt="" src="https://assets.leetcode.com/uploads/2022/12/14/treedrawio-3.png" style="width: 181px; height: 181px;">
24+
<pre><strong>Input:</strong> root = [1,2,null,3], k = 1
25+
<strong>Output:</strong> 3
26+
<strong>Explanation:</strong> The largest level sum is 3.
27+
</pre>
28+
29+
<p>&nbsp;</p>
30+
<p><strong>Constraints:</strong></p>
31+
32+
<ul>
33+
<li>The number of nodes in the tree is <code>n</code>.</li>
34+
<li><code>2 &lt;= n &lt;= 10<sup>5</sup></code></li>
35+
<li><code>1 &lt;= Node.val &lt;= 10<sup>6</sup></code></li>
36+
<li><code>1 &lt;= k &lt;= n</code></li>
37+
</ul>
38+
</div>

0 commit comments

Comments
 (0)