Ctrl K

Root Equals Its Children's Sum

Easy
You get a binary tree with exactly three nodes: the root root, its left child and its right child. Return True if the root's value equals the sum of its two children's values, and False otherwise.
Example 1
root=tree_node([7, 9, -2]) → True

9 + (-2) = 7, which is exactly the root's value.

Example 2
root=tree_node([4, 2, 3]) → False

2 + 3 = 5, but the root holds 4.

Example 3
root=tree_node([0, 0, 0]) → True
Constraints
  • The tree has exactly three nodes: the root, a left child and a right child
  • -100 ≤ node value ≤ 100
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsLeft, Node, Right EasyIdentical Trees EasyMirror-Image Tree EasyTree Height EasyBalanced Tree from a Sorted List Easy
loading Python…
Input
root=tree_node([7, 9, -2])
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 68 tests on the server, hidden ones included.