Amazon Coding Interview: Package Locker Assignment
Based on questions reported for Amazon interviews
The interviewer opens
Hi, and thanks for joining; welcome to your interview for the software engineer role at Amazon. We'll work through one coding problem together, and I'd like you to think out loud as you code. If you need to step out or take a break, you can pause any time with the Pause button at the top right of your screen.
The problem is about assigning packages to lockers, the kind of thing a pickup-locker service has to get right. It's in the Problem tab on the right, so please read it through and ask me any questions before you start.
The problem
Assign packages to lockers.
lockers:{id, size}records; size "S" < "M" < "L".commands:"DEPOSIT <package_id> <size>"or"PICKUP <package_id>".
DEPOSIT takes the earliest free locker (in lockers order) of the smallest fitting size (its size or larger) and outputs its id, else "NO_LOCKER". PICKUP frees the package's locker and outputs its id, else "NOT_FOUND" if it isn't stored. Each package id is deposited successfully at most once. Return one output per command.
Example: lockers [A:S, B:M, C:L], commands ["DEPOSIT P1 M", "DEPOSIT P2 S", "DEPOSIT P3 S", "PICKUP P1", "DEPOSIT P4 L", "DEPOSIT P5 M"] → ["B", "A", "C", "B", "NO_LOCKER", "B"]
Up to 1,000 lockers and 10,000 commands.