Some test cases failing

please check code, some test cases are failing

your approach is incorrect.
think about this case 1 2 -1 3 -1 4 5 6 -1 -1 -1 -1 -1
your output will be only 2 1… but answer is 2 1 4 6.
think about better approach.

thanks

can you please draw the tree for the input you are giving?

this is very simple test case. its difficult to draw tree in this platform.
can’t you draw tree for this input?
you have written code for reading the input. this is not even a minute task.

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.

can you explain the test case to me?
what does it mean this?
1 2 -1 3 -1 4 5 6 -1 -1 -1 -1 -1
----------------------------------1----------
-------------------------2----------------x
-------------------3---------x
-------------4----------5
-------6--------x x---------x
x-------x