The Equal Tree Partition coding problem asks you to determine if you can remove exactly one edge from a binary tree such that the resulting two subtrees have the same sum of node values. You are given the root of the tree, and the total sum can be positive, negative, or zero.
Amazon and other tech firms use the Equal Tree Partition interview question to evaluate a candidate's mastery of depth-first search interview pattern. It requires calculating subtree sums and identifying if any subtree sum is exactly half of the total tree sum. It’s a test of recursion, state management, and handling edge cases like duplicate sums or zero-sum trees.
This is a Post-order DFS problem.
total_sum / 2 exists in the set.Suppose the tree is:
5
/
10 10
/
2 3
5 + 10 + 10 + 2 + 3 = 30.30 / 2 = 15.10 + 2 + 3 = 15.Subtree sum problems are almost always solved with post-order traversal (bottom-up). Practice this until you can compute and store subtree properties in a single pass.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Insufficient Nodes in Root to Leaf Paths | Medium | Solve | |
| Maximum Average Subtree | Medium | Solve | |
| Binary Tree Coloring Game | Medium | Solve | |
| Maximum Product of Splitted Binary Tree | Medium | Solve | |
| Delete Leaves With a Given Value | Medium | Solve |