Locker Bank

Asked at GooglePhone screen

Reported by the problem's creator, not verified

A locker room has lockers numbered 1 to n. LockerBank(n) starts with every locker free. A customer is a string and holds at most one locker at a time. A freed locker can be handed out again immediately.

Each test drives one instance: init holds the constructor arguments and operations is a list of [method, [args]] calls; the output lists every call's return value.

Examples

  1. Example 1

    Input: init = [3], operations = [["last",[]],["store",["ann"]],["store",["bo"]],["store",["ann"]],["store",["cy"]],["store",["dee"]],["last",[]],["pickup",["bo"]],["store",["dee"]],["last",[]],["pickup",["zed"]],["last",[]],["pickup",["ann"]],["pickup",["ann"]],["store",["ann"]],["last",[]]]

    Output: [-1,1,2,-1,3,-1,3,2,2,2,-1,2,1,-1,1,1]

    Explanation: ann gets locker 1, bo gets 2, a second store for ann fails with -1, cy gets 3 and dee finds the bank full. After bo leaves locker 2, dee gets 2. Failed calls never change last(), which stays at the locker from the latest successful store.

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.