Dashboard
LC #637
Average of Levels in Binary Tree
Pattern · ?AmazonGoogle
Problem
Return the average value of nodes on each level of a binary tree.
Constraints
- 1 ≤ n ≤ 10⁴
- -2³¹ ≤ Node.val ≤ 2³¹ − 1
Example
- Input
- root = [3, 9, 20, 15, 7]
- Output
- [3.0, 14.5, 11.0]
- Why
- L0 avg: 3/1=3, L1 avg: (9+20)/2=14.5, L2 avg: (15+7)/2=11
Spot the pattern
Which pattern cracks it?
Hints
One at a time