https://hack.codingblocks.com/app/contests/2022/1258/problem
in the sample output why 5 is not included
https://hack.codingblocks.com/app/contests/2022/1258/problem
in the sample output why 5 is not included
Consider all the nodes are placed on x axis and 1 is placed at x = 0. Now if you go towards left then x decreases and if you go right x increases. So basically you have to print the topmost node for every x you discover. Here 5 is at x = 0, but we have already seen 1 at x = 0, so we print 1 instead of 5.
See this link for more clarity https://www.geeksforgeeks.org/print-nodes-top-view-binary-tree/
the link which you sent me is about the top view of a bt but the question is about bottom view
Oh my bad, but in this as well same logic is used, 1 ,5 and 6 occupy the same x coordinate.
Now 1 is at topmost level so it’s ignored.
But for 6 the reasoning is given that it is towards right, so its considered lower,( So it depends on question to question, here they are taking this as comparison). So you can say that for nodes having same x coordinate, and same height, choose the one which is towards right in original tree.
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.