PIXELBANKv8.2.1
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

Test Results

0/0
Run code to see test results.