Return the nodes of a binary tree level by level from top to bottom.
Level Order Traversal
gfgGiven the root of a binary tree, collect the node values level by level, starting from the root level and moving downward. Nodes on the same depth should appear together in left-to-right order.
Produce a list of levels, where each level is a list of the values encountered at that depth.
root.Example 1
Input
root = [3,9,20,null,null,15,7]
Output
[[3],[9,20],[15,7]]
Explanation
The root is on the first level, 9 and 20 are on the second level, and 15 and 7 are on the third level.
Example 2
Input
root = []
Output
[]
Explanation
An empty tree has no levels.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.