Code RoomGroup transactions
MediumPrep Room Coding #786

Group transactions

CodingAlgorithms & data structuresMid–Senior~25 min

You are given a list of transaction records, each a dict with keys 'user', 'amount' (int cents), and 'currency' (string). Group the transactions by (user, currency) and return a list of dicts with keys 'user', 'currency', 'total' (sum of amounts), and 'count' (number of transactions). Sort the output by 'user' ascending, then 'currency' ascending. Amounts may be negative (refunds). The input list may be empty.

Implement
aggregate_transactions(records: list[dict]) → list[dict]
Examples
in[[{"user":"a","amount":100,"currency":"USD"},{"user":"a","amount":50,"currency":"USD"},{"user":"b","amount":200,"currency":"EUR"}]]out[{"user":"a","count":2,"total":150,"currency":"USD"},{"user":"b","count":1,"total":200,"currency":"EUR"}]
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
[[{"user":"a","amount":100,"currency":"USD"},{"user":"a","amount":50,"currency":"USD"},{"user":"b","amount":200,"currency":"EUR"}]][{"user":"a","count":2,"total":150,"currency":"USD"},{"user":"b","count":1,"total":200,"currency":"EUR"}]not run yetsample