question:https://www.hackerrank.com/challenges/tree-top-view/copy-from/174241125
in challenge section of cb it is passing all the test cases but on hacker rank it is not passing all the test cases
Top view binary tree
The code which i have share is the one i have submitted on hacker rank
It’s just link to the question, not actual code link!
@nmaurya760 your logic to print top view is incorrect!
see for top view, mark a horizontal and vertical distance (say its h,d for root, as you move left it becomes h-1,d+1 and for right it becomes h+1,d+1) .
Now for every h your answer is the node with minimum corresponding d.
You may also do it with BFS.
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.