PIXELBANKv9.1.0
Menu

Implement Queue using Stacks

Implement a FIFO queue using only two stacks. Support push, pop (remove front), peek (get front), and empty.

Output the result of pop, peek, and empty operations.

Example:

Input:
push,1;push,2;peek;pop;empty
Output:
1
1
False
Reasoning:
  • We start with an empty queue and apply the given operations in sequence: push,1 and push,2 add elements 1 and 2 to the queue.
  • The peek operation returns the front element of the queue, which is 1, since the queue is implemented as a FIFO data structure.
  • The pop operation removes the front element from the queue, which is also 1, and returns it.
  • The empty operation checks if the queue is empty after the pop operation; since there is still one element (2) left in the queue, it returns False.

Constraints:

  • 1 <= val <= 9
  • At most 100 operations
  • All pop and peek calls are valid
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.