Pop operation means, we need to pop out the top element from the Stack.
If we store the same element in the queue that we have in stack, the top element of stack will be the last element in the Queue.
Suppose there are 2 Queues, Q1 and Q2.
Q1 has 'n' elements, now we have to perform pop operation. It means we need the last element from the Queue.
So, we'll dequeue every element except the last element from Q1 and enqueue in Q2.
This Step will Take
#Dequeue= n-1 step
#Enqueue= n-1 step
Now Dequeue from Q1(this will be the Pop operation), it'll take 1 step. Total number of Dequeue step is increased by 1.
#Dequeue= n-1 step + 1 step = n step
Now, we'll also have to restore the (n-1) element from Q1 to Q2,
So, we'll dequeue every element from Q2 and enqueue in Q1. As there are n-1 element so, n-1 dequeue and n-1 enqueue
Total #Dequeue= n step + n-1 step = 2n -1
Total #Enqueue= n-1 step + n-1 step = 2n - 2