Binary Tree Right Side View - aloalgo

Binary Tree Right Side View

Medium

You are given the root of a binary tree.

Your task is to return the values of the nodes visible when standing on the right side of the tree, ordered from top to bottom.

Return a list of the values of the visible nodes.

Example 1

Input
123
Output
[1, 2, 3]
Explanation:

From the right side, you can see nodes with values 1 (level 0), 2 (level 1), and 3 (level 2).

Example 2

Input
12354
Output
[1, 2, 4, 5]
Explanation:

From the right side, you can see nodes with values 1 (level 0), 2 (level 1), 4 (level 2), and 5 (level 3).

Example 3

Input
None
Output
[]
Explanation:

An empty tree has no nodes, so the right side view is empty.

Loading...
Input
123
Output
[1, 2, 3]

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!