Failed to print the order required

https://ide.geeksforgeeks.org/YfVtDkyHeF

this is the link to the code and I don’t understand the error in it

@arjun_121 you are building it normally but you have to build by calculating mid and all(it should be balanced)

Approach

  • Get the Middle of the array and make it root.
  • Recursively do same for left half and right half.
    • a) Get the middle of left half and make it left child of the root created in step 1.
    • b) Get the middle of right half and make it right child of the root created in step 1.

Prateek Bhaiya had taught this way.So why it is needed to be implementd the other way.

I have also read that approach but Prateek Bhaiya has taught this method and it also a simple and better approach according to me . So why this is not working.

@arjun_121 yes but there are diff type of ways to build it you have to do it acc to the question statement
if output given is sorted like in this case you cant build normally as it will form a skewed tree (ineffecient)

you mean that if input is in sorted order we need to implement the other approach

@arjun_121 no i was saying that to tell you that it is not better app everytime.
you have to build acc to the problem statement everytime

thanks I understood that how it will form a skewed tree. I will implement the other method . Thanks a lot.

you are welcome :smiley: