Deduplicate change stream
Deduplicate a change-data stream keeping the latest version per key. You are given events as [key, version, payload] where key is a string, version is an int (higher = newer), and payload is a string. Multiple events may share a key. Produce the materialized table: for each distinct key, keep only the event with the highest version (versions are unique within a key). Return the surviving events as [key, version, payload] sorted ascending by key.
Implement
dedup_latest(events: list[list]) → list[list]Examples
in
[[["a",1,"old"],["a",3,"new"],["b",2,"x"]]]out[["a",3,"new"],["b",2,"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
[[["a",1,"old"],["a",3,"new"],["b",2,"x"]]][["a",3,"new"],["b",2,"x"]]not run yetsample