AlgoUniversity
  • Go Back
Discussion
Print Right View :

Author

Rishabh Verma

Difficulty Level : Medium

Submissions : 192

Asked In : Amazon

Marks :15

: 4 | : 0

You are given a binary tree with n nodes, a numbers is written on each node, -1 represents the null node.

you have to print right view of the tree.

Input

First line contains a single integer n where ($$$1 \le n \le $$$ 2^18).

Second line contains n space separated integers $$$A_i$$$ written on $$$i$$$th node where ($$$-1\le A_i \le n$$$) for all $$$i$$$ such that ($$$1 \le i \le n$$$).

Output

Print the right view of binary tree.

Examples

Input
7
1 2 3 -1 5 -1 4
Output
1 3 4 
Input
7
1 2 3 4 -1 5 -1
Output
1 3 5 
Input
1
1
Output
1 

Note

In case 1:

1, 3 and 4 are right view of the given tree.

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.