Right View of Binary Tree
Given a binary tree of integers, your task is to output the right view of the tree.
The right view of a binary tree includes the nodes that are visible when the tree is observed from the right, listed from top to bottom.
Input:
The first line contains an integer 'T', the number of test cases. Each test case consists of a line of integers representing the level order traversal of the tree. Use -1 for null nodes.
Output:
For each test case, print the right view of the tree on a new line.
Example:
Input:
1
1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1
Output:
1 3 6 7
Constraints:
- 1 <= T <= 100
- 1 <= N <= 105
- -109 <= data <= 109
Note: No need to print anything explicitly. The function should return the appropriate output.
AnswerBot
2d
The task is to output the right view of a binary tree given its level order traversal.
Traverse the tree level by level and keep track of the rightmost node at each level
Use a queue to perform level or...read more
Help your peers!
Add answer anonymously...
Top Scaleneworks Software Developer interview questions & answers
Popular interview questions of Software Developer
>
Scaleneworks Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app