Two testcases are going wrong

for input

1 2 3 -1 4 -1 5 -1 -1 -1 6 -1 7 -1 8 -1 -1
desired
o/p
2 1 3 5 6 7 8

ur output is wrong

this question can be done easily using map
store the first element of each new level ( vertical level)

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.