Can u please tell where I am getting wrong as according to me code is quite correct.
Getting wrong output
Hello @Hk199977,
-
Your Code is failing for the test case like:
1 6 2 8 7 4 3 11 -1 9 -1 5 -1 -1 -1 -1 -1 10 -1 -1 -1 -1 -1
Visualising the Tree:
_______________________________1
_________________6 _________________________2
________8 ________________7 ________4 ________________3
_____11 ________________9 ________5
____________________10
Correct it. -
You can refer to this video for an optimised approach.
Feel free to ask if you don’t understand anything.
Feel free to ask if you face any difficulty.
Hope, this would help.
Give a like if you are satisfied.
Hello @Hk199977,
Your code for building tree will not work for this type of input.
I have corrected it:
Refer to the comments for better understanding.
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.