Restaurant Waitlist with Exact-Size Tables
Problem statement
Process operations against an initially empty restaurant waitlist.
JOIN id sizeappends a party unless that ID is already waiting.LEAVE idremoves that party when present and otherwise does nothing.SERVE tableSizeremoves and returns the earliest waiting party whose size is exactlytableSize, orNONEif no exact-size party waits.
An ID may join again after leaving or being served. Only SERVE operations produce output.
Function
processExactWaitlist(operations: String[][]) → String[]Examples
Example 1
operations = [["JOIN","A","4"],["JOIN","B","2"],["JOIN","C","4"],["SERVE","4"],["SERVE","4"]]return = ["A","C"]Exact-size parties are served in their join order.
Example 2
operations = [["JOIN","A","3"],["JOIN","A","3"],["LEAVE","A"],["LEAVE","A"],["SERVE","3"],["JOIN","A","3"],["SERVE","3"]]return = ["NONE","A"]Duplicate operations are idempotent, and A may rejoin after leaving.
Example 3
operations = []return = []No operations produce no service results.
Constraints
0 <= operations.length <= 200000.- Party IDs contain
1through20letters or digits. - Party and table sizes are integers in
[1,100000]. - Operation rows have the exact arity shown above.