Binary Tree Zigzag Level Order Traversal
Given the root of a binary tree, return the zigzag level order traversal of its node values: left-to-right on the first level, right-to-left on the next, alternating for each subsequent level.
Open official problem prompt ↗Output the tree's values grouped by depth, but read each level in an alternating boustrophedon (zigzag) direction.
Like reading a scroll written boustrophedon style — the first line left-to-right, the next right-to-left, snaking back and forth down the page.
- Input
- root = [3, 9, 20, null, null, 15, 7]
- Output
- [[3], [20, 9], [15, 7]]
- Why
- Level 0 = [3] left-to-right; level 1 read right-to-left = [20, 9]; level 2 left-to-right = [15, 7].
The number of nodes is in the range [0, 2000]-100 <= Node.val <= 100