Magicsheet logo

Root Equals Sum of Children

Easy
12.5%
Updated 8/1/2025

Root Equals Sum of Children

What is this problem about?

The Root Equals Sum of Children interview question gives you a binary tree with exactly three nodes: the root and its two children. You must determine if the root's value equals the sum of its two children's values. This is a trivially simple tree problem used primarily as a warm-up or introductory exercise.

Why is this asked in interviews?

Microsoft, Meta, Amazon, and Google ask this problem as a screening warm-up to assess basic binary tree access, node property retrieval, and a simple arithmetic check. It validates that candidates understand tree node structure (accessing .val, .left, .right) and can write clean, minimal code without over-engineering.

Algorithmic pattern used

The pattern is direct node property access and arithmetic comparison. Access root.val, root.left.val, and root.right.val. Return root.val == root.left.val + root.right.val. This is O(1) time and O(1) space. Since the problem guarantees exactly three nodes (root + two children), no null checks are needed for the children.

Example explanation

Tree:

    10
   /  \
  4    6

root.val = 10, root.left.val = 4, root.right.val = 6. 10 == 4 + 6 → true.

Tree:

    5
   / \
  3   1

5 ≠ 3 + 1 = 4 → false.

Tree:

    0
   / \
  0   0

0 == 0 + 0 → true.

Common mistakes candidates make

  • Adding unnecessary null checks when the problem guarantees the tree always has exactly three nodes.
  • Over-engineering with DFS/BFS traversal when a single three-line function suffices.
  • Checking children's children (there are none — the tree is exactly depth 1).
  • Using integer overflow checks when the constraints are trivially small.

Interview preparation tip

For the Root Equals Sum of Children coding problem, the binary tree interview pattern is at its simplest. Write the solution in 2–3 lines and move on. Interviewers at Microsoft and Meta use this as a test of code minimalism — don't add complexity that isn't needed. If you're asked "how would this change for a tree of any depth?", pivot to recursive DFS where each node checks if its value equals the sum of all leaf values in its subtree.

Similar Questions