← 返回 amazon 的题目列表Design an Amazon Locker System
类型:online_judge
Design an Amazon Locker System
Design an object-oriented system for an Amazon Locker package pickup service. The system contains multiple lockers. Each locker has a unique ID, a size, and a current state. A package has a unique tracking number, a size, and a status.
Implement these core operations:
Deliver a package: assign a currently available locker that can fit the package. On success, generate a pickup code and mark the package as stored.
Pick up a package: a customer provides a locker ID and pickup code. If they match, remove the package and make the locker available again.
Query a package: given a tracking number, return the package status and its assigned locker, if any.
Handle no availability: delivery must fail clearly if no available locker can fit the package.
Rules
Locker sizes are SMALL, MEDIUM, and LARGE; a larger locker can hold a smaller package.
A locker can contain at most one package at a time.
A package cannot be delivered more than once while it is already stored.
A pickup code is generated only after successful delivery and must match to retrieve the package.
Example
Given lockers:
L1: SMALL
L2: MEDIUM
L3: LARGE
When delivering a MEDIUM package P100, the system may assign L2 or L3 and return a pickup code. After a successful pickup using the correct locker ID and code, that locker becomes available again.