Today’s challenge
Build the solution
Write a function called restock(items) that decides which products need an order.
Return contract: A list of dictionaries containing sku and order_quantity, omitting products that need no order. The supplied driver wraps this list as orders and adds input_unchanged to verify that the original items are preserved.
Input bounds: 0–200 items; unique string SKUs; 0 ≤ quantity, minimum ≤ target ≤ 10,000.
Keep the supplied driver below your implementation. It reads one JSON object and prints your return value as JSON. The driver may also probe the behaviour described above; those probe fields are part of the test input.
- An item needs replenishment only when quantity is strictly below minimum.
- For a qualifying item, order target minus quantity units. Targets are always at least the minimum.
- Keep qualifying items in their original order. Do not change the input items.
The Twist: A shelf exactly at its minimum is acceptable today. Ordering it early changes the shop’s purchasing decision.
Sample
Input
{"items":[{"minimum":5,"quantity":3,"sku":"tea","target":12},{"minimum":5,"quantity":5,"sku":"rice","target":20}]}Expected output
{"input_unchanged":true,"orders":[{"order_quantity":9,"sku":"tea"}]}