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

Question

You are given `rows`, a list of dicts each with keys 'region', 'product', and 'amount' (an integer). Build a pivot table: return a list of [region, product, total] triples giving the summed 'amount' for every (region, product) pair that appears. Sort the output ascending by region, then by product. Regions/products are non-empty strings; amounts may be negative.

Implement
pivot_totals(rows: list[dict]) → list[list]
Examples
in[[{"amount":10,"region":"us","product":"a"},{"amount":5,"region":"us","product":"a"},{"amount":3,"region":"eu","product":"b"}]]out[["eu","b",3],["us","a",15]]
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.