FastPrepAssign Locker
Problems/Assign Locker

Assign Locker

Google logoGoogle● EasyINTERNFULLTIMEOAPHONE SCREENONSITE INTERVIEW

Updated Oct 2026

QuestionFunctionExamples

Problem statement

Special thanks: 🌷 A special thank you to our lovely, amazing frenz for sharing this question and its Last Seen information, including October 18, 2026! (∩˃o˂∩)♡ 🩷

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?

Historical occupancy follow-up

How would you extend the system to retrieve lockers that were occupied during a requested time span? Record the assignment and release times for each occupancy interval, then explain how to index that history for repeated time-range queries.

Clarify whether the query means any overlap or full containment, how interval endpoints and ongoing assignments are handled, and whether repeated occupancy intervals should produce one locker ID or several records. This discussion does not change the judged assignLocker interface or its returned last-assigned locker number.

Function

assignLocker(clients: String[]) → int

Examples

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 interview questions

  • Minimum Piano Hand Raises and Thumb PositionsONSITE INTERVIEW · Seen Dec 2026
  • Swap Adjacent in LR StringONSITE INTERVIEW · Seen Dec 2026
  • Top Ten Largest FilesPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Count Winning Dice Face PairsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Find a Failing Test PairONSITE INTERVIEW · Seen Nov 2026
  • Logger Rate LimiterPHONE SCREEN · Seen Nov 2026
  • Logger Rate Limiter with Every-Arrival HistoryPHONE SCREEN · Seen Nov 2026
  • Minimum Cars for Rental RequestsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Minimum Operations to Make a SubsequenceOA · Seen Nov 2026

Similar questions at other companies

  • ID Allocator with Assign and ReleaseSnap Inc. · PHONE SCREENSnap Inc. interview questions
  • Top K Frequent ElementsEricsson · ONSITE INTERVIEWEricsson interview questions
  • Top-K KOLs by Total LikesTikTok · ONSITE INTERVIEWTikTok interview questions
  • Assign Server Numbers by TypeOura · OA
  • Worker Task Assignment Part 1 - Balance WorkloadStripe · ONSITE INTERVIEWStripe interview questions
  • Bank Accounts with Transfers and a Richest LookupRippling · PHONE SCREENRippling interview questions
  • Fixed Window Average and ModeNuro · PHONE SCREENNuro interview questions
  • Merge Event PreferencesAirbnb · PHONE SCREEN · ONSITE INTERVIEWAirbnb interview questions
  • Top K Frequent ElementsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Paged KV Cache AccessNVIDIA · PHONE SCREENNVIDIA interview questions

Interview reports that mention this question

  • Google OA: What It Tests (2026)

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int assignLocker(String[] clients) {
      // write your code here
    }

}
Checking account…