Does this question also require the knowledge of maps??
using map this question become easy
but you can also do this without map
- This approach is based on the level order traversal. We’ll keep record of current max so far left, right horizontal distances from the root.
- And if we found less distance (or greater in magnitude) then max left so far distance then update it and also push data on this node to a stack (stack is used because in level order traversal the left nodes will appear in reverse order), or if we found greater distance then max right so far distance then update it and also push data on this node to a vector.
- In this approach, no map is used.