Root Equals Sum of Children

You are given the root of a binary tree that has exactly 3 nodes: the root, its left child and its right child. Return true if the root value equals the sum of the values of its two children, and false otherwise.

30:00

Root Equals Sum of Children
easy
Free written solution
Topics
Companies

You are given the root of a binary tree that has exactly 3 nodes: the root, its left child and its right child. Return true if the root value equals the sum of the values of its two children, and false otherwise.

Example 1:
Input: {"root":[10,4,6]}
Output: true
Constraints:
  • The tree consists only of the root, its left child, and its right child.

  • −100≤Node.val≤100-100 \leq \text{Node.val} \leq 100

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"root":[10,4,6]}

The root holds 10. Put it on one pan of the scale; its two children go on the other.

10root4left6right10? + ?

root.val = 10, children = ?

checking whether the scale balances

Variables
VariableValue
root.val10
left.val?
right.val?
children-
DepthFunction Call
Stack empty
0/4