Binary Tree Zigzag Level Order Traversal

TopicDifficultyCompanies
Binary Tree
MEDIUM
Amazon
Microsoft

Given the root of a binary tree, return the zigzag level order traversal of its nodes' values. The zigzag traversal is done from left to right, then right to left for the next level and alternate between.

Example

Input: Given binary tree [5,8,2,null,null,6,4]
5
/ \
8 2
/ \
6 4

Output: Return its zigzag level order traversal as:
[
[5],
[2,8],
[6,4]
]

Code Editor

Practice and Learn

Best way to learn is through solving real problems. Practice this problem in this code editor.