Back to DSA
Binary Tree Zigzag Level Order Traversal
mediumTraverse a binary tree level by level, but alternate the reading direction at each depth: left-to-right for the first level, right-to-left for the second, left-to-right for the third, and so on. Return the values grouped by level.
Examples
Example 1:
Input:
root = [1,2,3,4,5,6,7]Output:
[[1],[3,2],[4,5,6,7]] Example 2:
Input:
root = [9]Output:
[[9]]Hints
1234567