We should consider Q2 to be an array of size greater than length 4, then only the answer will come.
Step 0: Enqueue 1 in Q2, it is already sorted,
Step 1: Enqueue 2 in Q2 i.e 1,2
Step 2: perform 1 dequeue and 1 enqueue simultaneously for 1 time in Q2 i.e 2,1 (head pointing at 2 now)
Step 3: enqueue 3 in Q2 i.e 2,1,3
Step 4: perform 1 dequeue and 1 enqueues in simultaneously for 2 times in Q2 i.e 2,1,3 → 1,3,2 → 3,2,1 (head pointing at 3 now)
Step 5: Enqueue 4 in Q2 i.e 3,2,1,4
Step 6: perform 1 dequeue and 1 enqueues in simultaneously for 3 times in Q2 i.e 3,2,1,4 → 2,1,4,3 → 1,4,3,2 → 4,3,2,1
So the number of enqueue operations in Q1 is 0.
The question was bad in the sense that it didn’t say that the array size of Q2 is greater than 4 so solving conventionally with rear and front keeping the size limitation will not work same with the case if we consider it a circular queue