Skip to main content

Posts

Showing posts with the label Implement stack from Queues

Implement Stack Using Queues [EASY/IMPORTANT]

Company: Grofers, DE-Shaw, CouponDunia, Amazon, Adobe, Accolite, Snapdeal, Oracle, Kritical Solutions Question: Implement a Stack using 2 queue  q1  and  q2  . Input : The first line of the input contains an integer ' T ' denoting the number of test cases. Then T test cases follow. First line of each test case contains an integer  Q  denoting the number of queries .  A Query  Q  is of 2 Types (i)  1 x   (a query of this type means  pushing  'x'  into the stack) (ii)  2     (a query of this type means to pop element from stack and print the poped element) The second line of each test case contains  Q  queries seperated by space. Output: The output for each test case will  be space separated integers having  -1  if the stack is empty else the element poped out from the stack .  You are required to...