mediumTreesPure DSA~20 min
What You See From the Right of a Tree
Looking at a binary tree from the right side, you see exactly one node per depth — the rightmost. Return those visible node values top to bottom.
Problem
Given the root of a binary tree, return the values of the nodes you can see ordered from top to bottom when looking at the tree from the right side.
Input
A binary tree root.
Output
A list of the rightmost node values per level.
Constraints
- 0 <= number of nodes <= 100
- -100 <= node value <= 100
- The tree may be unbalanced.
Examples
Example 1
Input
root = [1,2,3,null,5,null,4]
Output
[1,3,4]
Levels show 1, then 3, then 4 from the right.
Example 2
Input
root = [1,null,3]
Output
[1,3]
Each level's rightmost node is visible.