Medium · Trees

Print side view

Given the root of a binary tree, return the values of the nodes you can see standing on its right side, ordered from top to bottom (the rightmost node of each level).

Examples

Example 1

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

Output: [1, 3, 4]

Example 2

[1,2,3,4,5]

Output: [1, 3, 5]

Rebuild it in the studio

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

More Trees problems