Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Solution: Reverse Level Order Traversal

Problem Statement

Given a binary tree, populate an array to represent its level-by-level traversal in reverse order, i.e., the lowest level comes first. You should populate the values of all nodes in each level from left to right in separate sub-arrays.

Example 1:

Example 2:


  • The number of nodes in the tree is in the range [0, 2000].
  • -1000 <= Node.val <= 1000


This problem follows the Binary Tree Level Order Traversal pattern. We can follow the same BFS approach




Like the course? Get enrolled and start learning!