Tree BFS - Level-order Traversal

trees · function

Description

Given the root of a binary tree, return its level-order traversal as a
list of lists, where each inner list contains the node values at that
depth (left to right).

Example:
        3
       / \
      9   20
         /  \
        15   7

Level-order: [[3], [9, 20], [15, 7]]

The level grouping is the point of this drill: it forces you to track
level boundaries on the queue, not just enqueue/dequeue blindly.

Constraints

- 0 <= number of nodes <= 1000
- Node values are integers
- Return [] for an empty tree
solution.py
output
Run the cases to see results here.