FastPrepConstant-Time Restaurant Waiting List

Constant-Time Restaurant Waiting List

Bloomberg LP logoBloomberg LP● MediumNEW GRADONSITE INTERVIEW
Learn

Problem statement

Maintain a queue of unique waiting customer IDs:

  • add: append customers[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^5 valid operations.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public String[] runRestaurantQueue(String[] operations, String[] customers) {
  // Write your code here.
}
operations["add","add","add","move","seat","seat"]
customers["A","B","C","C","",""]
expected["null", "null", "null", "null", "A", "C"]
Checking account…