Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6380 |

@mb1973 | 5642 |

@Quandray | 5233 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4610 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3413 |

Complete Leaderboard | |

Handle | Score |

@sanskar94511 | 603 |

@akashverma4 | 363 |

@swastik8750 | 300 |

@nishunishuraj18 | 286 |

@surajmamgai | 264 |

@anks9013 | 222 |

@nayan2709 | 213 |

@burhanuddinbohra72 | 212 |

@realname | 203 |

@amank8975 | 203 |

@manmeetkaur18102000 | 202 |

Complete Leaderboard |

Given a Binary Tree. Check whether all of its nodes have the value equal to the sum of their child nodes.

**Example 1:**

**Input:
** 10
/
10
**Output: **1**
Explanation: **Here, every node is sum of
its left and right child.

**Example 2:**

**Input:
** 1
/ \
4 3
/ \
5 N
**Output: **0**
Explanation: **Here, 1 is the root node
and 4, 3 are its child nodes. 4 + 3 =
7 which is not equal to the value of
root node. Hence, this tree does not
satisfy the given conditions.

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **isSumProperty**() that takes the root Node of the Binary Tree as input and returns 1 if all the nodes in the tree satisfy the following properties. Else, it returns 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.

**Expected Time Complexiy: **O(N).

**Expected Auxiliary Space: **O(Height of the Tree).

**Constraints:**

1 <= N <= 10^{5}

1 <= Data on nodes <= 10^{5}

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Children Sum Parent

...