• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
February 10, 2024 |1.3K Views
PROBLEM OF THE DAY : 09/02/2024 | Check for Children Sum Property in a Binary Tree
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 Binary Tree but also build up problem-solving skills.

In this problem, we are a binary tree having n nodes. Check whether all of its nodes have the value equal to the sum of their child nodes. Return 1 if all the nodes in the tree satisfy the given properties, else it return 0.

For every node, data value must be equal to the sum of data values in left and right children. Consider data value as 0 for NULL child.  Also, leaves are considered to follow the property.

Example :

Input:
Binary tree
      35
     /   \
    20  15
   /  \  /  \
  15 5 10 5
Output: 
1
Explanation: 
Here, every node is sum of its left and right child.

Give the problem a try before going through the video. All the best!!!
Problem Link: https://www.geeksforgeeks.org/problems/children-sum-parent/1

Read More