Medium · Trees

Binary Tree Right Side View (Trees)

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

Core interview problems are free with a full runner and lessons; Pro opens the complete library.

More Trees problems