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.
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.
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.
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.
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.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Maximum Binary Tree II | Medium | Solve | |
| Sum of Root To Leaf Binary Numbers | Easy | Solve | |
| Leaf-Similar Trees | Easy | Solve | |
| Search in a Binary Search Tree | Easy | Solve | |
| Evaluate Boolean Binary Tree | Easy | Solve |