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
Detect Fraudulent Duplicate Charges
00:00
5 left

Detect Fraudulent Duplicate Charges

MediumPython

Problem

GEICO payment systems may receive repeated payment events caused by retries or duplicate submissions. Given an unsorted list of payment transactions, identify every pair of transactions that has the same customer, merchant, amount, and currency, and occurs within five minutes.

Return the matching pairs as zero-based index pairs referring to the original input order. A pair (i, j) is valid when i < j and the absolute timestamp difference is at most 300 seconds. Do not compare a transaction with itself. Return pairs sorted lexicographically.

Formal Specification

Implement find_duplicate_charges(transactions). Each transaction is a dictionary with integer customer_id, integer merchant_id, integer amount_cents, string currency, and integer timestamp fields. Return a list of two-element lists, where each list contains the original indices of one potentially duplicated charge.

A transaction may match multiple other transactions. For example, three matching charges within five minutes produce all three pairs.

Constraints

  • 0 <= len(transactions) <= 10^5
  • 0 <= timestamp <= 2^31 - 1
  • 0 <= amount_cents <= 10^9
  • 1 <= customer_id, merchant_id <= 10^9
  • currency is a three-letter uppercase code
  • The output may contain up to O(n²) pairs

Function Signature

def find_duplicate_charges(transactions):
Interviewer

Your question is Detect Fraudulent Duplicate Charges. 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.