Description
Solutions
Assign Locker
🤘 INTERN

An automatic locker system is introduced into the changing room. When a customer visits the changing room, the system works as follows:

  • If a customer has not been assigned a locker, the system assigns them the lowest available locker number;
  • If a customer has already been assigned a locker, the system opens and releases that locker. Afterwards, the locker can be reassigned to another customer.
  • The locker numbers start from 1. At the beginning of the day, all lockers are empty. The changing room is visited N times. Which locker is assigned to a customer for the last time?

    ⊹ ࣪ Credit to 𓆝⋆。˚ 77﹏𓊝﹏𓂁﹏⊹ ࣪ ˖

    Example 1:

    Input:  clients = ["Alice", "Eve", "Bob", "Eve", "Carl", "Alice"]
    Output: 2
    Explanation:
    - Locker 1 is assigned to Alice; - Locker 2 is assigned to Eve; - Locker 3 is assigned to Bob; - Eve releases locker 2; - Locker 2 is assigned to Carl; - Alice releases locker 1. The last assigned locker is locker 2, so the function should return 2.
    Constraints:
      N/A
    Thumbnail 0
    Testcase

    Result
    Case 1

    input:

    output: