InterviewBit Academy is now Scaler!
Learn Tech Skills from Scratch @ Scaler EDGE

Right view of Binary tree


Problem Description

Given a binary tree A of integers. Return an array of integers representing the right view of the Binary tree.

Right view of a Binary Tree: is a set of nodes visible when the tree is visited from Right side.



Problem Constraints

1 <= Number of nodes in binary tree <= 105

0 <= node values <= 109



Input Format

First and only argument is an pointer to the root of binary tree A.



Output Format

Return an integer array denoting the right view of the binary tree A.



Example Input

Input 1:

        1
      /   \
     2    3
    / \  / \
   4   5 6  7
  /
 8 

Input 2:

    1
   /  \
  2    3
   \
    4
     \
      5


Example Output

Output 1:

 [1, 3, 7, 8]

Output 2:

 [1, 3, 4, 5]


NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Right view of Binary tree on Interview Code Editor
Sign Up
to access hints and editorial solutions for Right view of Binary tree
Asked In:

Discussion


Loading...
Click here to start solving coding interview questions