Loading 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.
Example 1
Input: root = [1,2,3,null,5,null,4]
Output: [1,3,4]
Explanation: Looking from the right, you see the last node on each level: 1 on level 0, 3 on level 1 (it hides 2), and 4 on level 2 (it hides 5).
Example 2
Input: root = [1,null,3]
Output: [1,3]
Explanation: Each level has only one node, 1 and then 3, so both are visible.
Example 3
Input: root = []
Output: []
Explanation: The tree is empty, so nothing is visible.
Perform BFS level by level. The last node at each level is visible from the right side.
Run checks all cases above. Submit evaluates all test cases.