Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

119. Binary Tree Zigzag Level Order Traversal

MediumDay 35 of 60Trees & BST

Given the root of a binary tree, return its values level by level, but alternate the direction: the first level is read left to right, the next right to left, then left to right again, and so on.

Example 1
Input: root = [3,9,20,null,null,15,7]
Output: [[3],[20,9],[15,7]]
Example 2
Input: root = [1]
Output: [[1]]
Constraints
  • The number of nodes is in the range 0 to 2000
  • -100 <= Node.val <= 100
Hints
Frequently asked at: Amazon, Microsoft, Bloomberg, Flipkart
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min