Left View of Binary Tree
The first node visible at each level when the tree is seen from the left side.
Key concepts at a glance — for those who already know the basics.
Problem Statement
Left View of Binary Tree
Input: root = [1, 2, 3, null, 5, null, 4]
Output: [1, 2, 4]
Tree: 1 → left=2, right=3; 2's right=5; 3's right=4.
Input: root = [1, 2, 3, 4, 5, 6, 7]
Output: [1, 2, 4]
Perfect binary tree — leftmost nodes at each level.
Constraints
- The number of nodes in the tree is in the range [0, 100].
- Each node's value is in the range [-100, 100].
The Rule
First node seen at each level from the left
Equivalently: the first node you encounter per depth in a level-order (BFS) traversal.
How to Think
Process the tree level by level (BFS with a queue)
Each queue iteration handles exactly one full level.
Record the very first node dequeued at each level
That first node is the leftmost visible node at that depth.
Add left child first, then right child, to the queue
Ensures left nodes always precede right nodes in the queue.
Code
Example
Blue nodes are the left view: [1, 2, 4]
Complexity
Time
O(n)
Every node is enqueued and dequeued exactly once.
Space
O(w)
Queue holds at most the width of the widest level.
Interview Uses
Right View of Binary Tree
Same pattern, record the last node per level instead of the first.
Level order traversal
Foundational BFS pattern that left view builds on.
Maximum width of a tree
Same BFS loop, just track max queue size per level.
Vertical order traversal
Another view-based problem sharing similar BFS structure.
Ready to see it in action?
Step through the visualizer to watch the algorithm state update live.