Question
You are given a list of order records, each a dict with keys 'customer', 'category', and 'amount' (a non-negative integer). Compute, for each customer, the single category on which they spent the most in total, with ties broken by the alphabetically smallest category name. Return a dict mapping customer to that top category. Model this query without SQL.
top_category_per_customer(orders: list[dict]) → dict[str,str][[{"amount":10,"category":"books","customer":"ann"},{"amount":15,"category":"toys","customer":"ann"},{"amount":5,"category":"books","customer":"bob"}]]out{"ann":"toys","bob":"books"}State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.