Welcome to the Python screen.
The question is on your right: Optimize Duplicate Record Aggregation. Read through the requirements first.
Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?
At Acme Analytics, a Python batch job is timing out while processing a large list of event records. Each record is represented as a pair [record_id, value]. Multiple records may share the same record_id. Your task is to optimize the job by aggregating all values for the same record_id and returning the result sorted by record_id.
A naive solution scans the full list repeatedly for each ID, which is too slow on large datasets. Write an efficient function that processes the list in near-linear time.
records, a list of pairs [record_id, value], where both elements are integers.[record_id, total_value] such that each record_id appears once and total_value is the sum of all values associated with that ID, sorted in ascending order by record_id.def aggregate_records(records):