Print a binary tree level by level in alternating (zigzag) directions.
Unlock detailed company stats for this questionUpgrade
Print the nodes of a binary tree level by level, alternating direction: left to right, then right to left, and so on. For a full tree with nodes 1 to 7, the output is 1 3 2 4 5 6 7. Expected approach: BFS with two stacks alternating push order, or a queue with every second level reversed. Time O(n), space O(n).
Format · Virtual technical round.
Also asked as · Print a binary tree in zig-zag order.
Community answers
No answers contributed by the community yet.
Related questions
Binary Tree Zigzag Level Order TraversalRelated courses

Course

Course
Course
