Code Room
CodingMediumcod-g678
Subject Data wranglingLevel Mid–Senior~25 minCommon in Algorithms & data structures interviewsIndustries Software development

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.

Implement
top_category_per_customer(orders: list[dict]) → dict[str,str]
Examples
in[[{"amount":10,"category":"books","customer":"ann"},{"amount":15,"category":"toys","customer":"ann"},{"amount":5,"category":"books","customer":"bob"}]]out{"ann":"toys","bob":"books"}
What a strong answer looks like

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.

Run or narrate your approach, then ask the coach.