Check tree nodes equal subtree average
Company: Meta
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Overview: This question evaluates binary tree traversal and recursion skills, along with the ability to aggregate subtree values and verify numeric relationships between a node and its subtree average.
Constraints
- 0 <= n <= 100000 (n is the number of entries in the level-order array)
- -10^9 <= node value <= 10^9
- Input uses level-order with null for missing children
- Empty tree ([]) should return true
- Time: O(n), Space: O(n)
Hints
- Use a post-order traversal to compute (sum, count) for each subtree.
- For each node, check node.val == (subtree_sum // subtree_count).
- Building the tree from the level-order array can be done with a queue.