A logistics dispatcher is monitoring a supply convoy: a fixed line of N trucks queued to depart in order, each one carrying a shipment identified by an integer ID. The dispatcher's console processes a stream of Q commands, each one of:
Commands must be processed strictly in the order given. It is guaranteed that a NEXT or PEEK command is never issued while the line is already empty.
For every command, print exactly one line of output, in the order the commands were given:
Example 1
Input
3 10 20 30 7 NEXT PEEK PEEK NEXT HASNEXT NEXT HASNEXT
Expected
10 20 20 20 true 30 false
Explanation
NEXT departs the first truck (ID 10). PEEK then reports the ID of the new front truck (20) twice, without it departing. The next NEXT departs that truck (ID 20). HASNEXT reports true because one truck (ID 30) is still waiting. NEXT departs it (ID 30). The final HASNEXT reports false, since the line is now empty. Output in order: 10, 20, 20, 20, true, 30, false.
Example 2
Input
1 42 4 HASNEXT PEEK NEXT HASNEXT
Expected
true 42 42 false
Explanation
With a single truck carrying ID 42, HASNEXT first reports true. PEEK reports 42 without removing it. NEXT then departs that same truck, also reporting 42. The final HASNEXT reports false because the line is now empty. Output in order: true, 42, 42, false.
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 →