Code RoomPivot table aggregation
MediumPrep Room Coding #1004

Pivot table aggregation

CodingAlgorithms & data structuresMid–Senior~25 min

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.

0:00 of about 25 min
InputExpectedGot
[[{"amount":10,"region":"us","product":"a"},{"amount":5,"region":"us","product":"a"},{"amount":3,"region":"eu","product":"b"}]][["eu","b",3],["us","a",15]]not run yetsample