• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
November 07, 2024 |100 Views

PROBLEM OF THE DAY : 06/11/2024 | Root to Leaf Paths Sum

Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Yash Dwivedi We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Tree but also build up problem-solving skills.

Given a binary tree, where every node value is a number. Find the sum of all the numbers that are formed from root to leaf paths. The formation of the numbers would be like 10*parent + current (see the examples for more clarification).

Examples:

Input :     6
               /  \
             3     5
           /  \      \
         2     5      4
               /  \
             7     4

Output: 13997 Explanation : There are 4 leaves, resulting in leaf path of 632, 6357, 6354, 654 sums to 13997.
 

Give the problem a try before going through the video. All the best!!!
Problem Link: https://practice.geeksforgeeks.org/problems/root-to-leaf-paths-sum/1