Tree bottom view problem


The code is giving incorrect output

That’s because of the implementation you have applied. You have to create a map where key is the horizontal distance and value is a pair(a, b) where a is the value of the node and b is the height of the node.
You have taken a map of int and vector of int, and aren’t considering for horizontal distance and vertical distance too. Moreover, you haven’t also consider the case in which we have to compare the node with the existing one in map and if the height of the new node is greater we also have to update that in the Map.
Your build function works fine, i have checked it. It’s just the logic to make map for bottom view.

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.