3

PROBLEM OF THE DAY : 09/02/2024 | Check for Children Sum Property in a Binary Tr...

 7 months ago
source link: https://www.geeksforgeeks.org/videos/problem-of-the-day-09022024-check-for-children-sum-property-in-a-binary-tree/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Check for Children Sum Property in a Binary Tree

February 10, 2024 |150 Views
PROBLEM OF THE DAY : 09/02/2024 | Check for Children Sum Property in a Binary Tree
Problem of the Day, Data Structure and Algorithm, binary-tree
 Save  Share   Like
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

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK