Loading...
Loading...
Loading...
Simulate a queue with only two stacks (two Python lists used with append and pop). Commands: enqueue x, dequeue and front. dequeue removes and prints the oldest value. front prints it without removing. For an empty queue they print EMPTY.
Example 1
Input
6 enqueue 1 enqueue 2 dequeue enqueue 3 dequeue front
Output
1 2 3
Prints 1, 2 and 3.
Example 2
Input
2 front dequeue
Output
EMPTY EMPTY
Try the problem first. Open one hint at a time.
Push on an inbox stack. Serve from an outbox stack.
Move the inbox to the outbox only when the outbox is empty.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor