Update appNew update is available. Click here to update.
Topics

Top View

Moderate
0/80
Average time to solve is 42m
profile
Contributed by
12 upvotes
CognizantMakeMyTripAmazon
+7 more companies

Problem statement

Given a binary tree. Print the Top View of Binary Tree. Print the nodes from left to right order.

Example:
Input:

Alt text

Output: 2 35 2 10 2
Detailed explanation ( Input/output format, Notes, Images )
Sample Input 1:
 1
 5 35 10 2 3 5 2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
Sample Output 1:
2 35 5 10 2
Sample Input 2:
2
5 -1 6 -1 -1
5 6 -1 -1 -1
Sample Output 2:
5 6 
6 5 
Full screen
Console