Binary Tree Right Side View
Given the root of a binary tree represented as an array in level-order, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. **Examples:** ```typescript rightSideView([1, 2, 3, null, 5, null, 4]) // [1, 3, 4] rightSideView([1, null, 3]) // [1, 3] rightSideView([]) // [] ```
Solve It in the BrowserPractice Explaining It Out Loud
Optimal Approach
- Time complexity: O(n)
- Space complexity: O(h)
Visiting right child first in recursive DFS processes the rightmost visible node at each depth.
Follow-Up Questions Interviewers Ask About Binary Tree Right Side View
- Why visit the right subtree before the left subtree in DFS?
By visiting right first, the first node encountered at any new depth is guaranteed to be the rightmost node.
Practice the full problem with execution, tests, and AI code review in the interactive lab — then rehearse explaining your solution in a live voice mock interview.