TOP VIEW

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

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

Note: Return the nodes in any order.

Constraints

1 <= Number of nodes in binary tree <= 100000
0 <= node values <= 10^9 

For Example

Input 1:
            1
          /   \
         2    3
        / \  / \
       4   5 6  7
      /
     8 
Output 1:
    [1, 2, 4, 8, 3, 7]

Input 2:
            1
           /  \
          2    3
           \
            4
             \
              5
Output 2:
    [1, 2, 3]
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 TOP VIEW on Interview Code Editor
Sign Up
to access hints and editorial solutions for TOP VIEW

Discussion


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