Stack using queue, queue using stack


#1


#2

Option C is correct. In S1…

Say you are 1st pushing n elements into queue1 which take O(1) time. Then inorder to pop second element from top just poll n-2 elements from queue1 into queue2 and then remove the front element from queue1, it will be the 2nd element from top of stack. This action would take O(n) time. So S1 is correct…

Now in S2, say you inserted n elements in stack 1 and then reversed it using stack 2.This action takes O(n) time. Now you can simply remove 2nd top element from stack 2 to get the desired result which takes O(1) time…So both are correct