Sliding Window Velocity Check for UPI Payer Risk
Last updated: November 29, 2026
Quick Overview
Given a time-ordered stream of UPI payments (timestamp, payer, amount in paise), return the indices of payments that push a payer over either a count limit or an amount limit within the trailing window of T seconds.
PhonePe
November 29, 20260
0
0 solved
Given a time-ordered stream of UPI payments (timestamp, payer, amount in paise), return the indices of payments that push a payer over either a count limit or an amount limit within the trailing window of T seconds.
Velocity rules are one of the first lines of defense in PhonePe's risk stack, catching account takeover and mule patterns before an ML model even runs, and they must evaluate in microseconds per payment. The interviewer looks for a per-key sliding window with amortized O(1) updates and a precise definition of the window boundary.
What the Interviewer Expects
- Define the window boundary precisely (which old events fall out)
- Keep per-payer state: a deque of recent events plus a running sum
- Evict expired events lazily when that payer's next payment arrives
- Use integer paise, never floats, for amounts
- Give amortized complexity and memory bound
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
- The stream is out of order by up to a few seconds. How do you change the design?
- Memory grows with idle payers. How do you clean up state for payers who stopped transacting?
- How would you run this across many machines so all events for a payer see the same state?
- Should a flagged payment count toward the window if it was then blocked?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list of (ts, payer, amount_paise) sorted by ts, a window T, max_count, max_amount. A payment is flagged if, counting it and the same payer's payments with ts > now - T, the count ex...
High-Level Design
Keep a dictionary from payer to a deque of (ts, amount) plus a dictionary of running sums. For each payment, pop from the left of that payer's deque while the oldest entry is at or before ts - T, ...