Problem · Hash Table
Assign Locker
Learn this problemProblem statement
An automatic locker system is introduced into the changing room. When a customer visits the changing room, the system works as follows:
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﹏𓊝﹏𓂁﹏⊹ ࣪ ˖
Function
assignLocker(clients: String[]) → intExamples
Example 1
clients = ["Alice", "Eve", "Bob", "Eve", "Carl", "Alice"]return = 2- 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.
More Google problems
- Deduplicate Logs: Keep FirstONSITE INTERVIEW · Seen Jul 2026
- Deduplicate Logs: Keep LatestONSITE INTERVIEW · Seen Jul 2026
- Find a Template Across Binary-Tree LeavesONSITE INTERVIEW · Seen Jul 2026
- Maximum Programmer-Problem MatchingONSITE INTERVIEW · Seen Jul 2026
- Minimum Direction ViolationsONSITE INTERVIEW · Seen Jul 2026
- Stream Latest Log VersionsONSITE INTERVIEW · Seen Jul 2026
- Stream Unique Logs in Timestamp OrderONSITE INTERVIEW · Seen Jul 2026
- Top-K IP Addresses from File RecordsONSITE INTERVIEW · Seen Jul 2026