Binary Tree Right Side View
BFS last-of-level / DFS right-first
LeetCode 199 • Medium • Trees
Input: root = [1,2,3,null,5,null,4] → Output: [1,3,4]
Rightmost node at each level. BFS: take last of each level. DFS: right-first, first at each level.
TimeO(n)visit each node once
SpaceO(n)queue + result
Queue: 0
Result: [ ]
Processing
In Queue
Processed
Right-side (result)
Queue
empty
Level
[ ]
Result
[ ]
Ready
Press Play. BFS level-by-level. Take last node of each level = rightmost visible.