Failing one testcase

Refer for code:

hello @ambuj_0909
your code output is exactly same as test file output still it is showing wa.
image

once try this iterative approach

  • The idea here is to observe that, if we try to see a tree from its top, then only the nodes which are at top in vertical order will be seen.
  • Start BFS from root. Maintain a queue of pairs comprising of node(Node *) type and vertical distance of node from root. Also, maintain a map which should store the node at a particular horizontal distance.
  • While processing a node, just check if any node is there in the map at that vertical distance.
  • If any node is there, it means the node can’t be seen from top, do not consider it. Else, if there is no node at that vertical distance, store that in map and consider for top 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.