Vertical order traversal of tree wrong answer

link- https://www.interviewbit.com/problems/vertical-order-traversal-of-binary-tree/
my code-
https://ide.geeksforgeeks.org/uTYhTiw7NC

What do you want to know in this question?

My code is giving wrong answer on interviewbit. Can you check it.

you have written st.front() which is a function for queue and not for stack.

other than that it works fine for me…


please check on interview bit. Here, it is showing wrong answer-
test case- 43 460 3871 4698 8399 504 4421 7515 -1 4167 5727 -1 -1 3096 434 7389 2667 5661 1969 7815 4292 3006 9750 6693 -1 6906 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
Serialized representation of tree. and 1st no is total no of nodes including -1
my answer-
[8399 2667 1969 ] [3871 4167 5727 ] [460 5661 504 7815 4421 4292 9750 ] [4698 3096 434 ] [3006 7515 6693 ] [7389 ] [6906 ]
expected answer
[8399 2667 1969 ] [3871 4167 5727 ] [460 504 4421 5661 7815 4292 9750 ] [4698 3096 434 ] [7515 3006 6693 ] [7389 ] [6906 ]

https://ide.codingblocks.com/s/43426

I have corrected the code and commented the errors. It is accepted on interview bit and geeksforgeeks both.
Hope this helps.

1 Like

Do comment if you have any doubts regarding this. :slight_smile:

1 Like

I have used the stack, that was the main problem. Thank you so much for debugging.

No problem ,Keep coding!