Package Locker Station

Asked at Amazon· Screen

Reported by the problem's creator, not verified

Import another question

A package-locker station has a fixed set of numbered compartments, each with a size label such as "S", "M" or "L". A delivery driver deposits a package into a free compartment of a matching size and receives a one-time pickup code; the customer later enters the code to open the compartment. Time is a whole number of days now, and now never decreases from one call to the next within a test.

Examples

  1. Example 1

    Input: init = [["S","M","M","L"]], operations = [["deposit",["M",0]],["deposit",["M",1]],["deposit",["M",2]],["pickup",[1,3]],["deposit",["M",3]],["pickup",[1,4]],["pickup",[99,4]],["deposit",["S",4]],["deposit",["S",5]],["deposit",["XL",5]],["pickup",[2,7]],["pickup",[2,8]],["pickup",[3,9]],["open_expired",[9]],["open_expired",[11]]]

    Output: [1,2,null,1,3,"invalid","invalid",4,null,null,2,"invalid",1,[],[0]]

    Explanation: Compartments 1 and 2 are the medium ones, so the third medium deposit finds none. Code 1 opens compartment 1 on day 3 and frees it, so the next medium deposit reuses it (code 3); code 1 is then already used and 99 never existed. Only compartment 0 is small, so the second small deposit fails, and no compartment has size XL. Code 2 (deposited day 1) still works on day 7 but is used on day 8. Code 3 (day 3) opens compartment 1 on day 9. On day 9 no package is 7 days old; by day 11 the small package from day 4 is, so staff open compartment 0.

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.