Given the root of a binary tree, return the level-order traversal of its node values, grouped per level (left-to-right).
[]
[0, 10⁴].-1000 ≤ Node.val ≤ 1000Snapshot the queue length at the start of each level. That fixes where each level ends.
The answer lists the root, then everything one step below it, then everything two steps below, each row from left to right. So the work is to visit nodes by distance from the root, and to know where one distance ends and the next begins.
Time O(n)Space O(w)
The full walkthrough and code are part of Premium