Loading...
Loading...
Loading...
A support desk serves tickets in the order they arrive. ADD id puts a ticket in the line and SERVE handles the oldest waiting ticket. Simulate the desk with a queue.
ADD <id> or SERVE, where id is one word.SERVE, print the id of the ticket served, or NONE if no ticket is waiting.Example
Input
5 ADD T1 ADD T2 SERVE ADD T3 SERVE
Output
T1 T2
T1 arrived first, so it is served first; then T2.
Try the problem first. Open one hint at a time.
Use Queue<String> line = new ArrayDeque<>(); with offer for ADD.
poll returns the oldest ticket, or null when the queue is empty.
Print NONE when poll returns null.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor