Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Merge Duplicate Dataset Records

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

Your question is Merge Duplicate Dataset Records. 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 records records, where each record is a list [id, value, timestamp], merge all records with the same id. For each id, return one record [id, total_value, latest_timestamp] where total_value is the sum of all values for that id and latest_timestamp is the maximum timestamp seen for that id. Return the final list sorted by id in ascending order.

Constraints

  • 1 <= len(records) <= 10^5
  • records[i].length == 3
  • 1 <= id <= 10^9
  • -10^6 <= value <= 10^6
  • 0 <= timestamp <= 10^9

Function Signature

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