Back to problems

Assign Locker

Algorithm · Google · Medium

A self-service locker setup is used in a changing area. Each time someone enters, the following rules apply: When the visitor does not currently hold a locker, give them the unoccupied locker with the smallest number. When the visitor already has a locker, unlock it and return it to the available pool. That locker may then be given to a later visitor. Locker labels begin at 1. Initially, no locker is occupied. After N visits to the changing area, determine the locker number…

Checking your access…