PIXELBANKv8.2.1
Menu

Implement Stack using Queues

Implement a LIFO stack using only two queues. Support push, pop, top, and empty.

Output results of pop, top, and empty operations.

Example:

Input:
push,1;push,2;top;pop;empty
Output:
2
2
False
Reasoning:
  • We start with an empty stack and perform the given operations in sequence: push,1 and push,2, resulting in a stack with elements 1 and 2.
  • The top operation returns the last element added to the stack, which is 2.
  • The pop operation removes the last element added to the stack, which is also 2, leaving the stack with only element 1.
  • The empty operation checks if the stack is empty, which it is not, since it still contains element 1, so it returns False.

Constraints:

  • 1 <= val <= 9
  • At most 100 operations
Editor

Test Results

0/0
Run code to see test results.