• Tutorials
  • DSA
  • Data Science
  • Web Tech
  • Courses
July 31, 2024 |2.9K Views

Sum of nodes on the longest path from root to leaf node

  Share   Like
Description
Discussion

Given a binary tree containing n nodes. The problem is to find the sum of all nodes on the longest path from root to leaf node. If two or more paths compete for the longest path, then the path having maximum sum of nodes is being considered.
Examples: 
 

Input : Binary tree:
       4        
      / \       
     2   5      
    / \ / \     
   7  1 2  3    
     /
    6
Output : 13


Sum of nodes on the longest path from root to leaf node : https://www.geeksforgeeks.org/sum-nodes-longest-path-root-leaf-node/