TREE TOP VIEW : binary tree

In order to implement top view of the tree I was trying vertical order traversal but its giving incorrect output. Please look into it.

Hello @mverma_be19 have you seen any hint video for this question?
there is a particular way of doing this question.

There can be different ways but i think of the most simplest is from hashing.

No there’s no hint video provided.

I am doing it using map

see start from the root node and for root node store the value 0 in the map and for left node you decrement it by one and for the right node you will increment it by one.
and if the decreasing and the increasing mapped value is not zero then you will not edit that value.
otherwise you will store the node data value.
that will be top view of a tree.
Here for your reference i am attaching the code:


it is the much easy approach i have found in my coding life till now.
if you have any doubt you can ask here:
HappyLearning!!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.