Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Right View
MEDIUM
35 mins
26 upvotes
Trees
Topics (Covered in this problem)
Problem solved
Badge
Skill meter
Trees
-
-
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
Linked List
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Right View

Contributed by
Ekansh Saxena
Medium
yellow-spark
0/80
Avg time to solve 35 mins
Success Rate 65 %
Share
26 upvotes

Problem Statement

You have been given a Binary Tree of integers.

Your task is to print the Right view of it.

The right view of a Binary Tree is a set of nodes visible when the tree is viewed from the Right side and the nodes are printed from top to bottom order.

Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1 :
1
2 35 10 2 3 5 2 -1 -1 -1 -1 -1 -1 -1 -1
Sample Output 1 :
2 10 2
Explanation of The Sample Input 1:

Sample Input 1

The right view of the tree contains all the extreme-right elements in each level of the tree, including the head of the tree.
Sample Input 2 :
1
1 2 -1 3 -1 4 -1 5 -1 -1 -1
Sample Output 2 :
1 2 3 4 5
Explanation of The Sample Input 2 :

Sample Input 2

Reset Code
Full screen
Auto
copy-code
Console