Account Testing Velocity
MediumQueues · Visa
Fraudsters often "test" a stolen card by making many small attempts at the same merchant. You are given authorization events as [card, merchant, ts, approved], where ts is an integer number of seconds and approved is a boolean. Events are sorted by ts in non-decreasing order.
Only declined attempts (approved is False) matter. When a declined attempt for (card, merchant) happens at time T, count the declined attempts for that same card and merchant with timestamp t such that T - t < window, including the current one. If that count is at least threshold, the card is flagged.
Declines at different merchants are counted separately. Once a card is flagged it stays flagged.
Return the flagged card ids sorted in ascending order (each card at most once). Return an empty list if no card is flagged.
Example 1
- Input:
- events = [["c1", "m1", 0, False], ["c1", "m1", 4, False], ["c2", "m1", 5, False], ["c1", "m1", 9, True], ["c1", "m1", 9, False]], window = 10, threshold = 3
- Output:
- ["c1"]
- Explanation
- At
ts = 9, cardc1has declines at 0, 4 and 9 at merchantm1, all less than 10 seconds before 9, so the count reaches 3. The approved attempt at 9 is ignored, andc2only has one decline.
Example 2
- Input:
- events = [["c1", "m1", 0, False], ["c1", "m1", 5, False], ["c1", "m1", 10, False]], window = 10, threshold = 3
- Output:
- []
- Explanation
- At
ts = 10the decline at 0 is exactly 10 seconds old, and10 - 0 < 10is false, so it no longer counts. Only 2 declines are in the window.
Example 3
- Input:
- events = [["c1", "m1", 0, False], ["c1", "m2", 1, False], ["c1", "m1", 2, False]], window = 10, threshold = 3
- Output:
- []
- Explanation
- Card
c1has 3 declines in total, but only 2 atm1and 1 atm2, so no single merchant reaches the threshold.
Constraints
0 <= events.length <= 10^5- Each event is
[card, merchant, ts, approved]with string ids, integer0 <= ts <= 10^9, and booleanapproved eventsis sorted bytsin non-decreasing order1 <= window <= 10^9,1 <= threshold <= 10^5