Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Detect Fraudulent Duplicate Charges

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

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

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):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output