FrontendX
Binary Tree Right Side View
medium
Description
AI Assistance
Solution
Test Cases
Test Result
Submissions
Canvas
Binary Tree Right
Side View
Return the node values you can see when looking at the tree from the right side.
Examples
Example 1
Input:
[1,2,3,null,5,null,4]
Output:
[1,3,4]
Example 2
Input:
[1,null,3]
Output:
[1,3]
Hints
Hint 1
Use a queue to perform a level-order traversal (BFS) of the tree.
Hint 2
For each level, keep track of the last node encountered before moving to the next level.
Hint 3
Store the value of the last node of each level in the result list.
Related Problems
average-of-levels-in-binary-tree
binary-tree-level-order-traversal
binary-tree-zigzag-level-order-traversal
Binary Tree Right Side View
Return the node values you can see when looking at the tree from the right side.