Assign Locker
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Google's Assign Locker question hit the assessment circuit in August 2024, and it's deceptively simple on the surface. You're given a set of lockers and a set of people, and you need to assign each person a locker based on some constraint or preference. The trick is figuring out the optimization rule and spotting whether it's a greedy match, a graph problem, or something with hidden structure. If you blank on the pattern during the live OA, StealthCoder reads the exact problem statement and surfaces the solution in real time, invisible to the proctor.
Pattern and pitfall
Assign Locker typically boils down to either a matching problem (greedy assignment) or a constraint satisfaction puzzle. The common approach is to sort both arrays by distance or preference, then pair them greedily. If it's harder than that, you're dealing with a bipartite graph matching or assignment problem solvable with a hash table to track used lockers. The catch most candidates miss is reading the constraint carefully: are you minimizing total distance, avoiding conflicts, or just finding any valid assignment. Walk through the small examples first to nail the actual rule. During the OA, if the logic isn't clicking, StealthCoder decodes the problem and hands you the pattern, letting you code with confidence instead of guessing.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Assign Locker cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as assign cookies. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Google's OA.
Google reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Assign Locker FAQ
Is Assign Locker a greedy problem?+
Usually yes. Sort people and lockers, then pair them in order. The trap is assuming the rule without checking the examples. Read the constraint first: are you minimizing distance, avoiding collisions, or just assigning one-to-one. The examples will tell you if greedy works or if you need a smarter approach.
What if I can't figure out the constraint?+
Trace through the small examples by hand. Write down the input, the expected output, and the rule you think applies. If it doesn't match, adjust. Most Google OA problems reward this methodical read-the-problem-first approach over clever optimization.
Do I need to handle multiple people per locker?+
Unlikely. These problems almost always assume one person per locker, making it a matching or pairing problem. If the problem allows it, the constraint will say so explicitly. Read the input spec carefully.
What's the time complexity they're after?+
Greedy + sorting is O(n log n). If matching is harder, you might need O(n^2) or a graph algorithm. Google usually accepts O(n log n) for these medium-tier problems. Don't over-optimize unless you're hitting time limits on a large test case.
How do I prepare in 48 hours?+
Focus on sorting and array pairing problems. Practice two-pointer and greedy matching on LeetCode. Understand the problem constraint before coding. For the live OA, stay calm. If you blank, StealthCoder is your safety net to read the problem clearly and get unstuck.