Bottom Right View of Binary Tree Problem Statement

Your task is to identify and return the bottom right view of a given binary tree.

This involves viewing the binary tree from an angle of 45 degrees from the bottom right side.

Example:

binary tree

Explanation:
In the above binary tree, nodes {4, 5, 6} are visible from the bottom right. Nodes ‘1’ and ‘3’ are hidden behind node ‘6’, and node ‘2’ is hidden behind node ‘5’.

Input:

The first line contains an integer 'T' denoting the number of test cases.
The first line of each test case contains elements of the tree in level order format, separated by a space, with '-1' representing null nodes.

Output:

For each test case, output the array of values of visible nodes, sorted in ascending order.
Each test case output should be in a new line.

Example:

Input:
1
2 3
4 -1 5 6
-1 7 -1 -1 -1 -1
-1 -1
Output:
[4, 5, 6]

Constraints:

  • 1 <= T <= 100
  • 1 <= N <= 3000
  • -10^9 <= data <= 10^9 (data != -1)

Where 'N' is the number of nodes in the tree, and 'data' denotes the data within a tree node.

Time Limit: 1 sec

Note:

You do not need to print anything; this function is about implementing logic only.

Be the first one to answer
Add answer anonymously...
Paytm Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter