Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Merging Records from Mismatched JSON
00:00
5 left

Merging Records from Mismatched JSON

HardPython

Problem

Given these two JSON files with mismatched data formats, how would you programmatically identify and merge the records?

Implement merge_json_records(left_records, right_records). Each input is an array of objects. Recognize id, user_id, or userId as the identifier; email, email_address, or nested contact.email as the email; and name, full_name, or fullName as the name. Normalize email case and surrounding whitespace. Match by normalized email first, then identifier. Merge matched records into canonical id, name, and email fields, preserve non-null fields from both records, and let the right input override conflicting values. Return records in left-input order, followed by unmatched right records.

Example: [{"user_id":7,"full_name":"Ava","email_address":" AVA@x.com "}] and [{"id":7,"name":"Ava Chen","contact":{"email":"ava@x.com"}}] produce one merged record.

Constraints

  • 1 <= left_records.length + right_records.length <= 100000
  • Each record is an object with at least one identifier or email field
  • Identifiers contain at most 100 characters after conversion to text
  • Email matching is case-insensitive and ignores surrounding whitespace
  • Within each input, normalized identifiers and emails are unique
  • If both inputs identify a match, the email match takes precedence over the identifier match

Function Signature

def merge_json_records(left_records, right_records):
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

You need to log in / sign up to run or submit.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.