Deduplicate events
You receive a list of event dicts each with keys 'id', 'ts' (int timestamp), and 'status'. Deduplicate so that for each 'id' only the record with the largest 'ts' survives; if two records share the same id and ts, the one appearing later in the input wins. Return the surviving records sorted by 'id' ascending. The input may be empty and ids may repeat any number of times.
Implement
latest_per_id(events: list[dict]) → list[dict]Examples
in
[[{"id":1,"ts":10,"status":"old"},{"id":1,"ts":20,"status":"new"},{"id":2,"ts":5,"status":"x"}]]out[{"id":1,"ts":20,"status":"new"},{"id":2,"ts":5,"status":"x"}]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
solution.py
InputExpectedGot
[[{"id":1,"ts":10,"status":"old"},{"id":1,"ts":20,"status":"new"},{"id":2,"ts":5,"status":"x"}]][{"id":1,"ts":20,"status":"new"},{"id":2,"ts":5,"status":"x"}]not run yetsample