I have understood the approach but

i got the approach but is there any other way to solve the problem instead of using maps?

@Manvik-Arya-4391661007540658 yes it can be done without maps also,
maintain two arrays A,B
let current horizontal point(hp) be 0 for root
after that whenever you go right, do hp+1 and for left do hp-1,
obviously if you are somewhere left, hp is -ve and on right hp is +ve,
now if hp is -ve and abs(hp)>size(A) then insert it,
else ignore as a node already exists on top of it!
similar do with hp is +ve and abs(hp)>size(B),
answer will be (reverse A) + (root->data) + (B)
complexity is O(n)// both space and time

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.