Rolling 24-Hour Debit Spend Limit with Reversals and Captures
Last updated: November 29, 2026
Quick Overview
Implement a per-card spend limiter that approves or declines card authorizations so that the sum of live authorizations in any trailing 24-hour window never exceeds a limit, where authorizations can later be reversed (freeing capacity) or captured for a different final amount.
Onepay
November 29, 20260
0
0 solved
Implement a per-card spend limiter that approves or declines card authorizations so that the sum of live authorizations in any trailing 24-hour window never exceeds a limit, where authorizations can later be reversed (freeing capacity) or captured for a different final amount.
OnePay debit cards enforce daily spend limits, and card networks send authorizations, reversals, and final captures (a gas pump hold of $100 that captures at $42) as separate messages. This hard onsite question tests stateful design under amortized constraints and clear decisions about ambiguous events.
What the Interviewer Expects
- Maintain a per-card sliding window with amortized O(1) updates
- Reversals free capacity immediately without scanning the window
- Captures adjust the counted amount up or down
- Unknown or expired auth ids are handled as defined no-ops
- State the boundary rule for the 24-hour window precisely
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
- A capture comes in higher than the authorization (tips at a restaurant). Should that ever push the card over its limit, and what do you do?
- How would you shard this across servers while keeping per-card decisions consistent?
- Authorizations must answer in under 50 ms. Where does this state live?
- How would you support a separate ATM withdrawal limit on the same card?
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 arrive in time order. auth(t, id, card, cents) is approved if live total in the window (t - 86400, t] plus cents is at most the limit. reverse(t, id) removes that authorization from the tot...
High-Level Design
Per card, a deque of (time, auth_id) in arrival order and a running total. A dictionary live maps auth id to its card, time, and current amount. Expiry pops from the deque front. Reversal deletes ...