InferenceAI

Enter at least two characters to search.

Start free

Zigzag Level Order

mediumTrees25 min25 XP

Return the node values level by level, going left to right on the first level, right to left on the second, and so on.

Trees are given in level order as a list, with None for a missing child (for example [3, 9, 20, None, None, 15, 7]).

Examples

EXAMPLE WALKTHROUGHclassic

A guided view of the published example, not a trace of your code.

INPUT[[3,9,20,null,null,15,7]]
TASKzigzag_levels()
EXPECTED OUTPUT[[3],[20,9],[15,7]]

Start with the input values shown in this example.

Example 1 of 3

Input: values = [3,9,20,null,null,15,7]

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

Explanation: classic

Input: values = [1]

Output: [[1]]

Explanation: single

Input: values = []

Output: []

Explanation: empty

Hint 1

Do a normal level-order traversal and reverse every other level.

Topics

DSATreesPython