Your question is Efficient Transaction Aggregation. 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.
Instacart wants a compact summary of order activity across its stores. Given a large list of completed order records, aggregate each store's total revenue, number of orders, and number of unique customers without repeatedly scanning the input.
Implement aggregate_store_metrics(transactions). The input is a list of dictionaries, where every record contains:
store_id: a string identifying the storecustomer_id: a string identifying the customeramount_cents: a non-negative integer order amount in centsReturn a dictionary keyed by store_id. Each value must be a dictionary with exactly these keys: total_revenue_cents, order_count, and unique_customer_count. Store results may appear in the order each store is first encountered.
def aggregate_store_metrics(transactions):