mediumTreesPure DSA~20 min
Org Broadcast Levels
A company-wide announcement cascades down the reporting tree: the CEO hears it first, then their direct reports, then the next level, and so on. Produce the list of employees grouped by the level at which they receive the message.
Problem
Given the root of a binary tree, return its level-order traversal: a list of lists where each inner list holds the node values at one depth, top to bottom.
Input
The root of a tree with n nodes (0 ≤ n ≤ 2·10^4), shown in level order with null for missing children.
Output
A list of lists of integers, one per level.
Constraints
- 0 ≤ n ≤ 20,000
- Node values fit in a 32-bit int
- An empty tree yields an empty list
Examples
Example 1
Input
root = [3, 9, 20, null, null, 15, 7]
Output
[[3], [9, 20], [15, 7]]
Depth 0 is [3], depth 1 is [9, 20], depth 2 is [15, 7].
Example 2
Input
root = [1]
Output
[[1]]
A single node forms one level.