Design a system for in app ordering at DoorDash.
Implement a function that processes an ordered stream of cart operations. Add operations must validate menu availability and stock. Remove operations must validate that the item is in the cart, remove up to the requested quantity, and restore the released stock. Operation IDs are idempotent: only the first occurrence is processed. Return accepted and rejected operation IDs, the final cart, total price in cents, and remaining stock.
Function: def process_order(menu, operations):. menu maps item IDs to {price, stock} objects. Each operation has operation_id, type (add or remove), item_id, and positive quantity.
Return a dictionary with keys accepted_operation_ids, rejected_operation_ids, cart, total_cents, and remaining_stock.
def process_order(menu, operations):