A parking allocator needs more than a free-space count. Vehicles have size requirements, tickets have a lifecycle and departures must release capacity only once. A repeated departure request is ordinary retry behavior, so the component must handle it deliberately.
You implement four bounded policies on supplied fictional records. Choose the smallest compatible stall so a small vehicle doesn't consume scarce large capacity. Resolve equal options with a stable ID. Billing uses started intervals after an inclusive grace period; the units are part of the exercise contract rather than a real price. Keep occupancy within both its lower and upper bounds. Each task can use a different internal design as long as the observable transitions preserve those rules.
import json
def process_payload(payload: str) -> str:
data = json.loads(payload)
free = list(data['stalls'])
result = []
for size in data['vehicles']:
fitting = [row for row in free if row['size'] >= size]
chosen = min(fitting, key=lambda row: (row['size'],row['id'])) if fitting else None
result.append(chosen['id'] if chosen else None)
if chosen:
free.remove(chosen)
return json.dumps(result,separators=(',',':'))
An exact fit is valid and a stall cannot serve two active tickets. Select from free compatible stalls before changing the allocation state. This straightforward design scans free stalls per vehicle; the stable policy matters before an indexed optimization.