29. Sum of nodes on the longest path
GFG solution to the Sum of Nodes on the Longest Path problem using DFS.
🧩 Problem Description
📘 Examples
Example 1
Input: root = [4,2,5,7,1,2,3,null,null,6]Output: 13
Explanation:Longest path is 4 → 2 → 1 → 6, sum = 4+2+1+6 = 13Example 2
Input: root = [1,2,3,4,5,6,7]Example 3
🔒 Constraints
✅ My Approach
DFS Returning (Length, Sum)
📝 Time and Auxiliary Space Complexity
🧑💻 Code (C++)
🧑💻 Code (Java)
🐍 Code (Python)
🧠 Contribution and Support
📍Visitor Count
Last updated