does not produce the right output when push and pop differently
What is problem in this code.. push efficent stack using 2 queues
@rohitkandpal683 The problem is in your pop and top functions:-
In pop function you are required to remove the last element from queue q1 so initialize i = 1 and after the while loop remove the last element of by q1.pop() as it is not needed now.
In top funnction you are returning the arr[cs-1], have ever think it you are maintaining the arr or not, how can you just return it.
One better way to see the top element in your code will be, just pop the element and then again push, also return the popped element.