Loading...
Loading...
A booking site keeps a waiting list in a list, in order. Process the commands in order. JOIN <name> adds a person at the end. VIP <name> adds a person at the front. CANCEL <name> removes the first person with that name and prints Cancelled <name>, or No such name if nobody has it. SERVE removes the first person and prints Served <name>, or Nobody waiting if the list is empty. SHOW prints Waiting: [a, b, c]. JOIN and VIP print nothing.
CANCEL, SERVE and SHOW command, in order.Example
Input
8 JOIN Asha JOIN Ravi VIP Meena SHOW CANCEL Ravi CANCEL Zed SERVE SHOW
Output
Waiting: [Meena, Asha, Ravi] Cancelled Ravi No such name Served Meena Waiting: [Asha]
Try the problem first. Open one hint at a time.
Read each command with sc.next(); read the name with another sc.next() only for the commands that have one.
add(0, name) puts a person at the front. remove(name) returns false when nobody matches.
Check isEmpty() before remove(0).
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor