Given a binary tree, complete the function that returns true if the tree satisfies the following property:
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.
The first line consists of T test cases. The first line of every test case consists of N, denoting the number of edges in the tree. The second and third line of every test case consists of N, nodes of the binary tree.
Return 1 if the given tree satisfies the given property else return 0.
This is a function problem. You need to only complete the given function isSumProperty() that returns 0 or 1. The printing is done by the driver code.
1 <= T <= 100
1 <= N <= 100
4 1 L 4 3 R 3 3 L
10 8 L 10 2 R 8 3 L 8 5 R 2 2 L
Testcase 1: Tree is like:
Here, every node is sum of its left and right child.
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.