Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Deduplicate Records by Composite Key

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Deduplicate Records by Composite Key. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Given a list of record dictionaries records, a list of field names key_fields that form a composite key, and a field name timestamp_field, return a new list with duplicate records removed. Records are duplicates if all values in key_fields match. For each composite key, keep only the record with the largest value in timestamp_field.

Constraints

  • 1 <= len(records) <= 10^5
  • Each record contains all fields listed in key_fields and timestamp_field
  • 1 <= len(key_fields) <= 5
  • Timestamp values are comparable with >

Function Signature

def deduplicate_records(records, key_fields, timestamp_field):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output