Ctrl K

Suspicious Card Payments

Medium
A bank's fraud monitor scans a payment log payments. Each record is a string "name,minute,amount,city": who paid, at which minute, how much and in which city. A payment is suspicious if at least one of these holds: - its amount is greater than 1000; - the same person has another payment in a **different** city no more than 60 minutes away from it (exactly 60 counts too). Return all suspicious records in any order. If an identical record appears in the log several times and is suspicious, it is returned that many times.
Example 1
payments=['ivan,100,300,omsk', 'ivan,150,40,tomsk', 'ivan,300,90,omsk'] → ['ivan,100,300,omsk', 'ivan,150,40,tomsk']

Ivan's first two payments were made in different cities 50 minutes apart, so both are suspicious. The third came 150 minutes after the second and is fine.

Example 2
payments=['olga,10,1500,kazan', 'petr,20,700,perm'] → ['olga,10,1500,kazan']

1500 is above 1000, so Olga's payment is suspicious on its own. Petr's payment is fine.

Example 3
payments=['anna,5,100,ufa', 'anna,65,100,sochi', 'boris,30,100,sochi'] → ['anna,5,100,ufa', 'anna,65,100,sochi']

Anna's payments are exactly 60 minutes apart; the boundary counts, so both are suspicious. Boris is a different person and does not affect them.

Constraints
  • 1 ≤ len(payments) ≤ 1000
  • Every record has the form "name,minute,amount,city"
  • Names and cities are 1 to 15 lowercase English letters
  • 0 ≤ minute ≤ 1000, 0 ≤ amount ≤ 10⁴
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsAnagram Buckets MediumA Subsequence of One Word Only MediumMost Searched Words MediumWord Grown Letter by Letter MediumMerge Contact Cards Medium
loading Python…
Input
payments=['ivan,100,300,omsk', 'ivan,150,40,tomsk', 'ivan,300,90,omsk']
Expected
['ivan,100,300,omsk', 'ivan,150,40,tomsk']

Run checks the first 3 tests in your browser. Submit checks all 81 tests on the server, hidden ones included.