InterviewBit Academy is now Scaler!
InterviewBit Academy is now Scaler Academy!

Sum binary tree or not

Given a binary tree. Check whether the given tree is a Sum-binary tree or not.

SumTree is a Binary Tree where the value of a node is equal to sum of the nodes present in its left subtree and right subtree.

An empty tree is SumTree and sum of an empty tree can be considered as 0.

A leaf node is also considered as SumTree.

Return 1 if it sum-binary tree else return 0.

Input Format

The only argument given is the root pointer of tree A.

Output Format

Return 1 if it is sum-binary tree else return 0.


1 <= length of the array <= 100000
0 <= node values <= 50

For Example

Input 1:
     /    \
    10     3
   /  \     \
  4   6      3
Output 1:

Input 2:
     /    \
    10     3
   /  \     \
  4   6      4
Output 2:
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Sum binary tree or not on Interview Code Editor
Sign Up
to access hints and editorial solutions for Sum binary tree or not


Click here to start solving coding interview questions