Author: Nicholas Smith
The Dockerfile defines a self-contained Go reference environment.
Build and run the program using Docker:
$ docker build -t challenge .
$ docker run --rm -it challenge --auth=<token>
Feel free to modify the Dockerfile as you see fit.
If go 1.23 or later is locally installed, run the program directly for convenience:
$ go run . --auth=<token>
When the shelf is full and no orders can be moved to their ideal storage, the system uses an eviction strategy that prioritizes discarding orders closest to expiration.
- Maintains a min-heap of shelf orders sorted by decay-adjusted expiry time
- Accounts for 2x decay rate for orders not at ideal temperature
- Evicts the order with the earliest adjusted expiry time
- O(log n) time complexity for eviction decisions
This eviction strategy minimizes waste by discarding orders that would expire soonest anyway, this maximizes the chance that other orders will be picked up successfully. The decay-adjusted calculation ensures fair comparison between orders with different temperature requirements on the shelf.
The heap accounts for when a hot or cold order is placed on the room-temperature shelf and the 2x decay by calculating each order's effective expiry time based on its actual decay rate. This means a cold order with 120 seconds of freshness will be prioritized for eviction over a room-temperature order with 60 seconds of freshness when both are on the shelf, since they'll both expire around the same actual time.