Tree top View Doubt


can someone help me in implementing this? The logic I’m trying to use is that I print the left subtree bottom to top and then the root and then the right subtree top to bottom.

And only the leftmost roots of left subtree and rightmost of right subtree

Hello @akankshaanand99,

This logic alone won’t give you the correct output.
You need some modification in it.

It will fail for test cases like:
____________1
_______2 ________3
___4 ______5 6
_______7 ________8
___9 ________________10
11

Required Output:
11 4 2 1 3 10
Your Output:
4 2 1 3

You may refer to this video.

Let me know if you face any issue.
Hope, this would help.
Give a like if you are satisfied.

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.