Restaurant Waitlist
Problem statement
Process operations against an initially empty restaurant waitlist.
JOIN id sizeadds a party with a unique string ID and positive party size to the back of the waitlist.DELETE idremoves the named party, which is guaranteed to be waiting.SERVE tableSizeremoves and returns the earliest still-waiting party whose size is at mosttableSize. ReturnNONEwhen no party fits.
Only SERVE operations produce output. Return those party IDs in operation order.
Function
processWaitlist(operations: String[][]) → String[]Examples
Example 1
operations = [["JOIN","A","4"],["JOIN","B","2"],["JOIN","C","6"],["SERVE","3"],["DELETE","A"],["SERVE","6"],["SERVE","10"]]return = ["B","C","NONE"]Party B is the first party that fits a table of size 3. After deleting A, party C is served next.
Example 2
operations = [["JOIN","P1","5"],["JOIN","P2","2"],["JOIN","P3","2"],["SERVE","2"],["SERVE","5"]]return = ["P2","P1"]P2 is earlier than P3 among parties that fit size 2. The next table can seat the earlier remaining party P1.
Constraints
1 <= operations.length <= 100000.- Party IDs contain letters or digits, have length from
1through20, and are unique across the entire operation sequence. - Party sizes and table sizes are integers from
1through100000. - Every
DELETEoperation names a currently waiting party.