Check is this code is correct for implementation of stack using 2 queues , in which the push operation is in O(N) time.
Stack using 2 queues
Forgot to mention the link
Hey @Gurjot,
Your code implementation is absolute right, whereas it does make push operation in O(n) time because in this method the newly entered element is always at the front of ‘q1’, so that pop operation just dequeues from ‘q1’. ‘q2’ is used to put every new element at front of ‘q1’.
Rest implementation is good . Hope it helped you 
1 Like
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.