A parcel relay behaves as a first-in first-out queue. Starting empty, it processes q operations, each one of:
ENQ x — append the integer x to the back of the queue.DEQ — remove the element at the front and report it. It is guaranteed the queue is non-empty.PEEK — report the element currently at the front, without removing it. It is guaranteed the queue is non-empty.Line 1: an integer q.
Next q lines: one operation each.
For every DEQ and every PEEK operation, in order, print the reported element on its own line.
DEQ and PEEK acts on a non-empty queue.Example 1
Input
6 ENQ 10 ENQ 20 PEEK DEQ PEEK DEQ
Expected
10 10 20 20
Explanation
Queue becomes [10, 20]. PEEK reports 10. DEQ removes and reports 10. PEEK reports 20. DEQ removes and reports 20.
Example 2
Input
5 ENQ 7 DEQ ENQ 8 ENQ 9 PEEK
Expected
7 8
Explanation
ENQ 7 then DEQ reports 7, emptying the queue. After ENQ 8 and ENQ 9 the front is 8, so PEEK reports 8.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →