As i build tree using level order traversal but acc. to it output must be 4 2 5 6 3 how it can be 4 2 6 3
Is output wrong in this question
Hello @Deepanshu_garg ,
To understand this output you have to imagine the physical structure of the tree.
For the given input set, the tree formed would look like following diagram:
________1
____2_______3
__4_____5
________6
What is happening here is 1,5 and 6 are co-linear i.e. they all lie on the same line.
As 6 comes after 5, thus 6 overlaps the view of 5 from bottom.
Hence, output is 4 2 6 3.
Hope, this would help.
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.