LeetCode 102 ·
Medium
Binary Tree Level Order Traversal
Return node values grouped by tree level, top to bottom.
Try it
Step through the core mechanic. The simulator below runs the bfs shape this problem is built on.
Walk the pattern
No dedicated step-through for this one yet. The shape is BFS — its pattern page has the interactive walkthrough, the reference implementation, and a five-problem progression that this problem sits inside.
The approach
BFS with a queue; at each step record the current queue size and pop exactly that many to bound one level, enqueuing children for the next. Each level becomes one output list.
| Aspect | Value |
|---|---|
| Pattern | BFS |
| Recognise it by | Visit nodes level by level. |
| Time complexity | O(n) |
| Space complexity | O(n) |
| Difficulty | Medium |
Who asks it
Companies known to ask this problem, from public LeetCode company-tag aggregations. A signal of where to expect it, not a guarantee.