DSA · Tree / BFS · #17
Binary Tree Level Order Traversal
Module 20 · difficulty 3/5·⏱ 30:00starts on first keystroke
Given the `root` of a binary tree, return the level-order traversal of its nodes' values — i.e. values grouped level by level, left to right, top to bottom. A node has the shape `{ val, left, right }` where `left` / `right` are child nodes or `null`. An empty tree is `null` and returns `[]`.
Examples
root = [3,9,20,null,null,15,7]→[[3],[9,20],[15,7]]root = [1]→[[1]]root = []→[]
Constraints
- · The number of nodes is in the range [0, 2000].
- · -1000 <= Node.val <= 1000
Session phases
A · Clarify
B · Approach
C · Complexity
D · Edges
E · Code
F · Tradeoff
G · Score
Phase A — Clarify
Ask questions about input bounds, types, and edge constraints.
Ask the coach clarifying questions about the problem.
When you've covered this phase, advance to the next.