Binary Tree Zigzag Level Order
Updated
Problem statement
You are given the root of a binary tree. Return its node values one level at a time. Read the root's level from left to right, the next level from right to left, and keep switching direction on each level after that.
Return one array per level. If the tree is empty, return an empty array.
The tree is given as a list of node values, read level by level and left to right within each level. null marks a missing child.
Function
zigzagLevelOrder(root: TreeNode) → List<List<Integer>>Examples
Example 1
root = [3,9,20,null,null,15,7]return = [[3],[20,9],[15,7]]Read left to right, the levels are [3], [9,20], and [15,7]. The second level is read right to left, so it becomes [20,9]. The third level goes left to right again, so it stays the same. This gives the output shown.
Example 2
root = []return = []The tree has no nodes, so it has no levels.
Constraints
- root is a valid binary tree with 0 through 2000 nodes.
- Every node value is between -1000 and 1000, inclusive.
More Apple Phone Screen questions
- LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Topological OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Subarray Product Less Than KPHONE SCREEN · Seen Nov 2026
- Evaluate DivisionPHONE SCREEN · Seen Nov 2026
- Reverse a Linked ListPHONE SCREEN · Seen Nov 2026
- Validate a BST with a Custom ComparisonPHONE SCREEN · Seen Nov 2026
- Design a Food Rating SystemPHONE SCREEN · Seen Oct 2026
- Days Until Poisoned Plants StabilizePHONE SCREEN · Seen Oct 2026
- Capture Surrounded Regions with Union-FindPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Maximum-Scoring Consecutive Tree LevelsJane Street · PHONE SCREENJane Street interview questions
- Minimum Edits to a Perfect Binary TreeSnowflake · PHONE SCREENSnowflake interview questions
- Find All Paths for a Name in a File SystemThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
- Binary Tree Spiral Level OrderAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Check a Complete Binary TreeGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
- Binary Tree Right Side ViewGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Same Binary TreeOdoo · PHONE SCREENOdoo interview questions
- Binary Tree Zigzag Level Order TraversalLinkedIn · PHONE SCREEN · ONSITE INTERVIEWLinkedIn interview questions
- Insert an Employee into an Organization HierarchyWaymo · PHONE SCREENWaymo interview questions
- Bottom View of a Binary TreeOracle · PHONE SCREEN · ONSITE INTERVIEWOracle interview questions
Apple interview experiences
- Apple SWE Phone Screen: Subarray Products: 1 Experience
- Apple New Grad SWE Java, Coding and Manager Rounds: 1 Experience
- Apple AI Coding and Related Interviews: 17 Experiences
- Apple India SWE New Grad Interviews: 5 Experiences
- Apple New Grad SWE Phone Screens: 12 Experiences (Part 3 of 3)
- Apple New Grad SWE and Embedded: 16 Experiences (Part 2 of 3)