Tree top view problem


getting no output error in all testcases.
pls tell the correct code.

Hi @yutikakhanna,
in ur build function, pass root as parameter since u r trying to find top view of a tree with root as the ‘‘root’’ node.
in ur present code, ur root is not getting updated and is NULL all d time because of which its not printing any output.

pls explain in the form of a code

i have updated ur current code. U can refer to dis for the modifications.

Moreover @yutikakhanna , the input of the tree will be given in level order format(in hacker blocks), so u also need to modify that since ur present code doen’t take input in that format.
Hope dis resolves ur doubt. if u still have any doubts, feel free to post them here.

all the testcases are showing wrong answer in this code

have u made the changes to the build function???
as i told, in ur current code, u r taking not taking input in level order format.
eg input={1,2,3,-1,-1,-1,-1}, ur present code is building tree like:
---------------1
-------------2
-----------3
whereas the tree that is being given as input need to be interpreted as :
---------------1
-------------2–3
So, try making some changes in ur build function

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.