Loading...
Loading...
A support desk handles urgent tickets first. ADD id priority adds a ticket; a bigger priority number is more urgent. SERVE handles the most urgent waiting ticket. If two tickets have the same priority, the one that was added earlier is served first.
ADD <id> <priority> or SERVE.SERVE, print the id of the ticket served, or NONE if no ticket is waiting.Example
Input
6 ADD T1 2 ADD T2 5 ADD T3 5 SERVE SERVE SERVE
Output
T2 T3 T1
T2 and T3 are both priority 5: T2 was added first. Then T1.
Try the problem first. Open one hint at a time.
Use a PriorityQueue of ticket objects with a Comparator.
Give each ticket a running arrival number. Compare by priority, highest first, and break ties by the smaller arrival number.
With Comparator.comparingInt(...) use .reversed() for the priority and thenComparingInt for the arrival number, or write one compare method.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor