Cloudkitchen 回家作业 java版实现,all test passed。供参考
补充内容 (2026-01-30 04:11 +08:00):
Backend Engineering Challenge
Build a real-time system for fulfillment of food orders in a delivery-only kitchen. Your system
should allow orders to be received, stored and eventually picked up. All of these events can
happen concurrently.
Order fulfillment
Food orders have the following attributes:
● ID . A short identifier (e.g., e6bc2 ) used to identify the correct order at pick up.
● Name . The name of food (e.g., Cheese Pizza ).
● Temperature . Ideal storage temperature: hot , cold or room .
● Price . Order price in dollars.
● Freshness . Duration (in seconds) the food remains fresh at its ideal temperature.
An order not stored at its ideal temperature degrades twice as quickly.
Placing orders
When a new order is received, the system instantly cooks the order and stores it until pick up.
The following options are available for storage:
● Cooler . Holds up to 6 cold orders at cold temperature.
● Heater . Holds up to 6 hot orders at hot temperature.
● Shelf . Holds up to 12 orders at room temperature.
To ensure the food remains as fresh as possible, the system should try to store a cooked order
at its ideal temperature. If the ideal option is full, the order must be placed on the shelf. If the
shelf is also full, the system should first move an existing, cold or hot order on the shelf to either
the cooler or heater, respectively, if there is room. If no such move is possible, an order stored
on the shelf must be selected – thoughtfully using a criteria of your choice – and discarded first
to make room for the new order.
Removing orders
When an order is picked up, it must be removed quickly without moving other orders around. No
action is taken by the kitchen if the order is not present.
If an order has exceeded its freshness duration at the time of pickup, it must be discarded
instead.
[PRIVILEGED & CONFIDENTIAL"temp": "hot", // Ideal storage temperature
"price": 10, // Price in dollars
"freshness": 120 // Freshness duration (in seconds)
[PRIVILEGED & CONFIDENTIAL]
},
...
]
Solve problem
Submits a solution to a test problem.
Request:
POST
Query params:
Name Type Description
auth string Authentication token (required)
Headers:
Name Type Description
x-test-id string Test id (required)
Content-Type string application/json
The body must contain a list of actions and parameters encoded as json as follows:
{
"options": {
"rate": 500000, // Inverse order rate (in microseconds)
"min": 4000000, // Min pickup time (in microseconds)
"max": 8000000 // Max pickup time (in microseconds)
},
"actions": [{
"timestamp": 1667667202596000, // Unix timestamp (in microseconds)
"id": "e6bc2", // Order id
"action": "place" // Action: place, move, pickup or discard
"target": "cooler" // Target: heater, cooler or shelf
},
...
]}
Response:
The body contains a string with the pass/fail test result. |