Constant-Time Restaurant Waiting List
Problem statement
Maintain a queue of unique waiting customer IDs:
add: appendcustomers[i], return null.seat: remove and return the first customer.move: swap the named customer with its immediate predecessor, or do nothing if already first; return null.
Implement every operation in O(1).
Function
runRestaurantQueue(operations: String[], customers: String[]) → String[]Examples
Example 1
operations = ["add","add","add","move","seat","seat"]customers = ["A","B","C","C","",""]return = ["null","null","null","null","A","C"]Moving C produces A,C,B; seats then remove A and C.
Constraints
- At most
10^5valid operations.