Binary Tree Level Order Traversal II
Problem Statement
You are given the root of a binary tree. Return the node values one row at a time, like a normal level order traversal, but from the bottom row up: the deepest row comes first, then the row above it, and the root's row comes last.
Inside each row, keep the usual order: left to right. Only the order of the rows is flipped.
The root of a binary tree. It can be empty (null).
In the examples, a tree is written in level order: the root first, then each row left to right. A null marks a missing child.
A list of rows, with the deepest row first and the root's row last. Each row is read left to right.
The top-down rows are [3], [9, 20] and [15, 7]. Reading them from the bottom up gives [15, 7], [9, 20] and [3]. Inside [15, 7] the order is still left to right.
A single node is one row.
No nodes, so no rows.
- • The number of nodes in the tree is in the range [0, 2000].
- • −1000 ≤ Node.val ≤ 1000
Pattern Recognition Clues
Recognising these key signals in the problem description immediately identifies the pattern:
Approach Complexity Ladder
Find the height, then for depth d from H − 1 down to 0, walk the whole tree and keep depth d
Run the normal BFS unchanged, then reverse the outer list once
Find the height H. Then, for depth d from H − 1 down to 0, walk the whole tree and collect the nodes at depth d. The rows come out bottom-up directly, so nothing needs reversing.
Recognition rule for this sub-pattern:
Unlock Complete Visual Walkthrough & Optimal C++
The interactive animated dry-run player, optimized C++ implementation, state invariant derivations, and edge-case breakdown for this question are part of Brute2Best Pro. The anchor question of every sub-pattern is completely free.
First anchor question per pattern, Part 1 LLD & Module 1 C++ basics are 100% Free forever.
How this concept connects to System Design & C++ Systems
Top engineering interviews test whether you understand how algorithms like Tree BFS translate into production architectures and low-level memory mechanics.
Foundations: Object-Oriented Principles in C++23
Class invariants, pure virtual interfaces, and RAII smart pointers.
Food Delivery System (Zomato Architecture)
Real-world machine coding application of algorithms and design patterns.
Pointers vs References Deep Dive
Pointer arithmetic and memory layout under the hood.
Virtual Method Table (vtable) & Memory Layout
Polymorphism, vptr overhead, and multiple inheritance in memory.