Node value equals average of its children
Problem Given a binary tree, check whether every node's value equals the average of its children's values. Clarify with the interviewer: direct children only (the common variant), integer vs exact average, and the single-child / leaf conventions.
Input / Output
- Input: the tree root.
- Output: boolean (or, per variant, the count of satisfying nodes).
Constraints
- Up to 10^5 nodes; a single O(n) traversal suffices.
Example
- Node 4 with children 3 and 5 → 4 == (3+5)/2 ✓. Node 4 with a single child 4 ✓. Leaves are vacuously true (no children).
asked …