Binary Tree Right Side View
Find the right side view of a binary tree using DFS that prioritizes right subtrees.
01The problem
Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.
text
1 <--- 1
/ 2 3 <--- 3
\ 5 4 <--- 4
Output: [1, 3, 4]Note: A left child can be visible if the right subtree is shorter! For example:
text
1 <--- 1
/ 2 3 <--- 3
/
4 <--- 4 (visible from right!)
Output: [1, 3, 4]Constraints
- The number of nodes in the tree is in the range
[0, 100]. -100 <= Node.val <= 100
Loading the rest of the lesson…