Binary Tree Level Order Traversal II - Problem
Given the root of a binary tree, return the bottom-up level order traversal of its nodes' values. This means traversing from left to right, level by level from leaf to root.
In other words, collect all nodes at each level, but return the levels in reverse order - starting from the deepest level and ending at the root level.
For example, if a tree has 3 levels, return the nodes in order: Level 3 → Level 2 → Level 1
Input & Output
Example 1 — Basic Tree
$
Input:
root = [3,9,20,null,null,15,7]
›
Output:
[[15,7],[9,20],[3]]
💡 Note:
Level order traversal gives [[3],[9,20],[15,7]]. Reversing gives [[15,7],[9,20],[3]] for bottom-up order.
Example 2 — Single Node
$
Input:
root = [1]
›
Output:
[[1]]
💡 Note:
Tree has only one level with one node. Result is [[1]].
Example 3 — Empty Tree
$
Input:
root = []
›
Output:
[]
💡 Note:
Empty tree returns empty result.
Constraints
- The number of nodes in the tree is in the range [0, 2000]
- -1000 ≤ Node.val ≤ 1000
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code