Binary Tree Level Order Traversal

Given the root of a binary tree, return its level order traversal — the node values grouped level by level, from left to right. A node's level is the number…

Given the root of a binary tree, return its level order traversal — the node values grouped level by level, from left to right. A node's level is the number of edges from the root to that node. The root is at level `0`; its children are at level `1`, and their children are at level `2`. Keep one list per level. If the tree has no nodes, return `[]` because there are no levels to collect.

- The number of nodes is in the range `[0, 2000]`. - `-1000 <= Node.val <= 1000` - The tree is given as a level-order array with `null` for missing children.

Example 1: input root = [3,9,20,null,null,15,7]; output [[3], [9, 20], [15, 7]]. Level 0 has `[3]` (the root); level 1 has `[9, 20]` (the root's children); level 2 has `[15, 7]` (the children of node `20`). Read each group from left to right and keep it as one list in the output.

Example 2: input root = [1]; output [[1]]. The root `1` is the only node at level `0`, so the output has one group, `[1]`.

Example 3: input root = []; output []. There are no nodes, so there is no level to collect. Return `[]`, not `[[]]`.

Category: Trees. Topic: trees. Difficulty: Medium. Patterns: bfs.