Medium · Trees

Binary Tree Zigzag Level Order Traversal

Given the root of a binary tree, return its zigzag level order traversal: one row per level, with level 0 read left to right, level 1 right to left, and alternating after that; an empty tree returns [].

Examples

Example 1

[3,9,20,null,null,15,7]

Output: [3] [20,9] [15,7]

Example 2

[1,2,3,4,5,6,7]

Output: [1] [3,2] [4,5,6,7]

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Trees problems