Skip to content

Commit d7039d4

Browse files
committed
Create README - LeetHub
1 parent ffe48c7 commit d7039d4

File tree

1 file changed

+50
-0
lines changed
  • Sum of the Longest Bloodline of a Tree (Sum of nodes on the longest path from root to leaf node) - GFG

1 file changed

+50
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Sum of the Longest Bloodline of a Tree (Sum of nodes on the longest path from root to leaf node)
2+
## Easy
3+
<div class="problems_problem_content__Xm_eO"><p><span style="font-size:20px">Given a binary tree of size&nbsp;<strong>N.</strong>&nbsp;Your task is to complete the function&nbsp;<strong>sumOfLongRootToLeafPath(),</strong>&nbsp;that find the sum of all nodes on the longest path from root to leaf node.<br>
4+
If two or more paths compete for the longest path, then the path having maximum sum of nodes is being considered.</span></p>
5+
6+
<p><strong><span style="font-size:20px">Example 1:</span></strong></p>
7+
8+
<pre><span style="font-size:18px"><strong>Input:</strong>
9+
4
10+
/ \
11+
2 5
12+
/ \ / \
13+
7 1 2 3
14+
/
15+
6
16+
<strong>Output:</strong> 13
17+
<strong>Explanation:</strong>
18+
<strong>4</strong>
19+
/ \
20+
<strong>2</strong> 5
21+
/ \ / \
22+
7 <strong>1</strong> 2 3
23+
/
24+
<strong>6</strong>
25+
26+
The highlighted nodes <strong>(4, 2, 1, 6)</strong> above are
27+
part of the longest root to leaf path having
28+
sum = (4 + 2 + 1 + 6) = 13</span></pre>
29+
30+
<p><strong><span style="font-size:18px">Example 2:</span></strong></p>
31+
32+
<pre><strong><span style="font-size:18px">Input: </span></strong><span style="font-size:18px">
33+
&nbsp; 1
34+
&nbsp; / \
35+
&nbsp; 2 3
36+
&nbsp; / \ / \
37+
&nbsp; 4 5 6 7</span>
38+
<strong><span style="font-size:18px">Output: </span></strong><span style="font-size:18px">11</span>
39+
</pre>
40+
41+
<p><span style="font-size:18px"><strong>Your Task:</strong></span><br>
42+
<span style="font-size:18px">You don't need to read input or print anything. Your task is to complete the function&nbsp;<strong>sumOfLongRootToLeafPath</strong></span><span style="font-size:18px"><strong>()&nbsp;</strong>which takes root node of the tree as input parameter and returns an integer denoting the sum of the longest root to leaf path of the tree. If the tree is empty, return 0.</span></p>
43+
44+
<p><span style="font-size:18px"><strong>Expected Time Complexity:</strong>&nbsp;O(N)<br>
45+
<strong>Expected Auxiliary Space:</strong>&nbsp;O(N)</span></p>
46+
47+
<p><span style="font-size:18px"><strong>Constraints:</strong><br>
48+
1 &lt;= Number of nodes &lt;= 10</span><sup><span style="font-size:15px">4</span></sup><br>
49+
<span style="font-size:18px">1 &lt;= Data of a node &lt;= 10<sup>4</sup></span></p>
50+
</div>

0 commit comments

Comments
 (0)