Flag Cards With Too Many Declines in a Rolling Time Window
Last updated: November 29, 2026
Quick Overview
Given an unsorted list of authorization events `(timestamp_seconds, card_fingerprint, outcome)`, return every card that has at least `n` declines within any window shorter than `w` seconds, along with the timestamp at which it first crossed the threshold.
Stripe
November 29, 20260
0
0 solved
Given an unsorted list of authorization events `(timestamp_seconds, card_fingerprint, outcome)`, return every card that has at least `n` declines within any window shorter than `w` seconds, along with the timestamp at which it first crossed the threshold.
Card testing, where fraudsters run many small authorizations against stolen numbers, is a constant problem that Stripe Radar defends against, and a velocity rule like this is the simplest building block. The interviewer checks that you pick a per-key sliding window, define the window boundary precisely and can talk about moving it to a streaming setting.
What the Interviewer Expects
- Group by card before windowing so one card's traffic does not affect another
- Ignore approvals and other outcomes when counting declines
- State the window boundary explicitly (here `t - start < w`) and test it
- Report the first time each card crosses the threshold, sorted deterministically
- Explain how the same logic works on a stream with bounded memory
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you process this as a stream where events arrive slightly out of order?
- How would you also catch attackers who rotate across many cards from one IP address?
- How would you bound memory when there are hundreds of millions of cards?
- What if the threshold should be a decline ratio rather than a raw count?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Events may be unsorted and contain many cards. A window covers declines whose timestamps satisfy t - first < w, so declines at 0 and 600 are not in the same 600-second window. Output `(card, first_f...
High-Level Design
Bucket decline timestamps per card, sort each bucket, then run a two-pointer window: advance right, shrink left while the span is too wide, and flag the card as soon as the window holds n declin...