Detect Near-Duplicate Charges Within Time and Amount Tolerance
Last updated: November 29, 2026
Quick Overview
Given one card's charges sorted by timestamp, find the earliest pair whose timestamps are at most T seconds apart and whose amounts differ by at most D cents, or return None if no such pair exists.
Capital One
November 29, 20260
0
0 solved
Given one card's charges sorted by timestamp, find the earliest pair whose timestamps are at most T seconds apart and whose amounts differ by at most D cents, or return None if no such pair exists.
Double swipes and retried online checkouts produce near-identical charges that Capital One wants to surface before a customer disputes them. This Power Day problem looks for a solution better than O(n^2) by combining a time-based sliding window with either an ordered set or amount buckets.
What the Interviewer Expects
- Explain why the brute force is O(n^2) and too slow
- Maintain only charges within the time window
- Bucket amounts with width D + 1 so a bucket holds at most one live charge
- Check neighboring buckets for the cross-boundary case
- Evict correctly when the window slides
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 solve it with a balanced BST or sorted list instead of buckets, and what are the trade-offs?
- How would you require the same merchant as well as close amount and time?
- How would you return every near-duplicate pair rather than the first?
- What changes if charges arrive as an unbounded stream across millions of cards?
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
(timestamp, amount_cents)sorted by timestamp, plusT >= 0andD >= 0. - Output:
(i, j)with i < j for the smallest j that has any match, or None. - Conditions: `t[j] - t[i] <...
High-Level Design
The time condition is a sliding window: keep only charges with t >= t[j] - T. For the amount condition, put each amount in bucket a // (D + 1). Two amounts in the same bucket differ by at most D, ...