Keep the latest record per key
A free easy coding practice problem from data. Solve it in JavaScript, TypeScript or Python and check your solution against fresh hidden tests — edge cases and random inputs — as often as you like.
- Difficulty
- Easy
- Type
- Function
- Topic
- Data
- Languages
- JavaScript, TypeScript or Python
Problem
records are change events [key, timestamp, value] (key and value strings, timestamp an integer). Deduplicate them: for each key keep only the record with the LARGEST timestamp; if several share that timestamp, keep the one that appears LAST in the input. Return the kept records (as [key, timestamp, value]) sorted by key ascending (character-code order). Up to 100 000 records.
Function signature
// JavaScript
function latestRecords(records)
// TypeScript
function latestRecords(records: any): any
// Python
def latest_records(records):Examples
latestRecords([["u1",5,"a"],["u2",3,"b"],["u1",9,"c"],["u1",7,"d"]])→[["u1",9,"c"],["u2",3,"b"]]latestRecords([["k",1,"first"],["k",1,"second"]])→[["k",1,"second"]]
How checking works
Run your code against the examples above, then submit a check: it runs on the server against hidden tests built fresh each time, including edge cases and random inputs. Practice is untimed and never affects a verified score; when you are ready, take a graded coding challenge to earn a badge.