Medium · Trees

Binary Tree Right Side View

Given the root of a binary tree, return the values of the nodes visible from its right side — the rightmost node at each depth — ordered from top to bottom (an empty tree gives []).

Examples

Example 1

[1,2,3,·,5,·,4]

Output: [1, 3, 4]

Example 2

[1,·,3] right-leaning

Output: [1, 3]

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Trees problems