Flag Cards Exceeding a Transaction Velocity Threshold
Last updated: November 29, 2026
Quick Overview
Given unsorted card transaction events (card_id, timestamp_seconds), a count k and a window length w, return every card that ever has at least k transactions within any window shorter than w seconds, along with the timestamp at which it first crossed the threshold.
PayPal
November 29, 20260
0
0 solved
Given unsorted card transaction events (card_id, timestamp_seconds), a count k and a window length w, return every card that ever has at least k transactions within any window shorter than w seconds, along with the timestamp at which it first crossed the threshold.
Velocity rules are one of the oldest risk signals in PayPal's fraud stack, so this sliding-window question is a natural technical screen. The interviewer looks for grouping by card, sorting per group, and a correct two-pointer window with a precise boundary definition.
What the Interviewer Expects
- Group events by card before applying the window
- Use a two-pointer window rather than checking all pairs
- Define the boundary clearly (half-open window)
- Return the first trigger time, stopping early per card
- Discuss streaming adaptation with a deque
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 do this on a live stream where events arrive slightly out of order?
- How would you support several rules at once (3 in 1 minute, 10 in 1 hour)?
- What memory does the streaming version need per card?
- How would you avoid flagging legitimate merchants like transit fare readers?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Window semantics: transactions at times t1 <= t2 are in the same window if t2 - t1 < w. A card is flagged the first time the window ending at some event contains at least k events. Output `(card, tr...
High-Level Design
Bucket timestamps by card, sort each bucket, then sweep with two pointers: the right pointer advances over events, and the left pointer advances while the window is too wide. The window size is `right...