Back to course home
0% completed
Vote For New Content
Reverse Level Order Traversal (easy)
Problem Statement
Given the root
of a binary tree, return the bottom-up level order traversal of its nodes' values. (i.e., the lowest level comes first in left to right order.)
Examples
Example 1
- Input: root = [1, 2, 3, 4, 5, 6, 7]
- Expected Output: [[4, 5, 6, 7], [2, 3], [1]]
- Justification:
- The third level has
4
,5
,6
, and7
nodes. - The second level has
2
and3
nodes. - The first level has a single node with the value
1
.
- The third level has
Example 2
- Input: root = [12, 7, 1, null, 9, 10, 5]
- Expected Output: [[9, 10, 5], [7, 1], [12]]
- Justification:
- The third level has
9
,10
, and5
nodes. - The second level has
7
and1
nodes. - The first level has a single node with the value
12
.
- The third level has
Example 3
- Input: root = [6,5,2,null,null,1,6,3,56,3]
- Expected Output: [[3,56,3],[1,6],[5,2],[6]]
- Justification:
- The fourth level has
3
,56
, and3
nodes. - The third level has
1
, and6
nodes. - The second level has
5
and2
nodes. - The first level has a single node with the value
6
.
- The fourth level has
Constraints:
- The number of nodes in the tree is in the range
[0, 2000]
. -1000 <= Node.val <= 1000
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible