Who leaves the queue next?
Warm-up · Trace the algorithm · about 5 min
Level order runs on this tree with a queue. Answer the prompts as the traversal runs: click the next node to be visited, then put all nodes in visit order.
Example 1
Input:
[["A","B","C","D","E",null,"F"]]
Output:
["A","B","C","D","E","F"]
Row by row, left to right.
Constraints
- The tree has 6 nodes, A to F
- Children join the queue left child first
Learn the idea first: Level-order traversal, a visual lesson.
More Level-order traversal problems
- Complete the level loop Warm-up
- Level order Standard
- Right side view Standard
- Average of levels Standard
- Zigzag level order Challenge