Catch Duplicate Payments

Medium ⏱ 12 min 62% acceptance ★★★★☆ 4.3
A duplicate payment is the same (customer_id, amount) occurring within 120 seconds. Write duplicates(payments) where each payment is (timestamp_seconds, customer_id, amount) sorted by time — return the list of indexes (into the input) flagged as duplicates of an earlier payment.

Examples

Example 1
Input
duplicates([(0, 7, 500), (60, 7, 500), (300, 7, 500)])
Output
[1]
Explanation

The 60 s repeat is flagged; the 300 s one is a fresh charge.

Constraints

  • Window: strictly within 120 s of the previous same-pair payment.
  • Compare to the most recent prior occurrence.

Topics

Business Logicfraud detection

Companies

StripeRazorpayPhonePe

Hints

Hint 1

Track last-seen time per (customer, amount) in a dict.

Hint 2

Update the timestamp even when flagged.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.