Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Right View of Binary Tree

XPChallenge Points: 20
levelLevel: Medium

You are given the root of a binary tree.

Imagine standing on the right side of the tree.
Return the values of the nodes you can see from top to bottom.


Example 1:

Input: root = [5,3,8,1,4,null,9]

Output: [5,8,9]

Explanation:

From the right side, you see 5 → 8 → 9.

Example 2:

Input: root = [7,2,10,1,null,8,12]

Output: [7,10,12]

Explanation:

Right side view shows 7 → 10 → 12.

Example 3:

Input: root = [1,null,2,null,3]

Output: Only right children are visible.

Example 4:

Input: root = []

Output: []

Explanation:

Empty tree, nothing to see.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result