Restaurant Waitlist

Asked at GoogleOnsite

Reported by the problem's creator, not verified

A restaurant keeps a waiting list of parties. Each party has a name and a number of people. Parties are served in the order they joined, but a party at the front can be passed over when it is too big for the free table.

Examples

  1. Example 1

    Input: init = [], operations = [["join",["ann",4]],["join",["bo",2]],["join",["cy",6]],["find_first_match",[3]],["find_first_match",[1]],["find_first_match",[6]],["delete",["ann"]],["find_first_match",[6]],["find_first_match",[6]],["delete",["bo"]],["find_first_match",[3]],["find_first_match",[10]]]

    Output: [null,null,null,"bo",null,"ann",null,"bo","bo",null,null,"cy"]

    Explanation: bo is the first party of size at most 3, so find_first_match(3) returns bo; nobody has a party of size 1. Table 6 fits ann first, and asking again returns ann because finding does not remove. After ann leaves, bo is first, and once bo leaves too, table 3 fits nobody and table 10 gets cy.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.