Your question is Predict Inventory Needs Function. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Meta Shop needs a lightweight demand forecast for each SKU based on recent daily sales. Implement a function that uses a recency-weighted moving average, then calculates how many units should be replenished to cover the lead time and forecast horizon.
For each SKU, consider at most the last window sales values. Assign weights 1, 2, ..., m to the selected values, where m is the number of values and the most recent day receives weight m. The forecasted daily demand is the weighted average. Required inventory is the ceiling of this forecast multiplied by lead_time + horizon. Return only the additional units needed after subtracting current inventory, never returning a negative value.
Implement forecast_inventory(sales_history, inventory, window, lead_time, horizon).
sales_history is a dictionary mapping SKU strings to arrays of nonnegative integers, ordered from oldest to newest.inventory is a dictionary mapping every SKU in sales_history to its current nonnegative unit count.window, lead_time, and horizon are positive integers.def forecast_inventory(sales_history, inventory, window, lead_time, horizon):