Binary Tree Right Side View
Given the root of a binary tree, imagine standing on the right side of it. Return the values of the nodes you can see, ordered from top to bottom — that is, the rightmost node at each depth level.
Open official problem prompt ↗Collect the rightmost node value at every depth of the tree, from the root down.
Stand to the right of a bookshelf: on each shelf (level) you can only see the book at the far right end; the ones behind it are hidden.
- Input
- root = [1,2,3,null,5,null,4]
- Output
- [1,3,4]
- Why
- Level 0 sees 1, level 1's rightmost is 3, and level 2's only node 4 (child of 3) is visible.
The number of nodes is in the range [0, 100]-100 <= Node.val <= 100