Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
Identify Frequent Duplicates in Large Dataset
00:00
5 left

Identify Frequent Duplicates in Large Dataset

HardPython

Problem

If 30% of a billion-record dataset contains duplicate transaction IDs, how would you efficiently identify the most frequent duplicates and optimize the Spark job?

Asked in the R2 PySpark stage. Write a Python function that takes a list of transaction IDs and returns the IDs with the highest duplicate counts, sorted by count descending then ID ascending.

Function Input

  • transaction_ids: list of strings or integers

Output

  • list of the most frequent duplicate IDs

Requirements

  1. Count only IDs that appear more than once.
  2. Return every ID tied for the maximum duplicate frequency.
  3. Optimize for large input by avoiding unnecessary full sorts when possible.

Constraints

  • 1 <= len(transaction_ids) <= 10^6
  • transaction_ids may contain strings or integers
  • Duplicate frequency is defined as total occurrences greater than 1
  • Return all IDs tied for the maximum duplicate frequency

Function Signature

def most_frequent_duplicates(transaction_ids):
Interviewer

Your question is Identify Frequent Duplicates in Large Dataset. Start with the requirements in the Question tab.

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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.