I am getting two test cases wrong can anyone tell the mistake
Stack is a First In Last Out type of data structure.
So when you transfer elements from stack a1 to a0 in lines 53 to 57, you change the order of elements that will be processed on the next iteration.
Example
6 2
3 4 7 6 5 9 (considering first element is the bottom most in the stack)
after 1st iteration
b1 = 6 4
a1 = 9 5 7 3
after 2nd iteration
b2 = 3 9
a2 = 7 5
output would be 4 6 9 3 5 7 (Correct output)
But your code produces 4 6 3 9 7 5