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
Coding & Algorithms
Software Engineer
Capital One
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

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
Sliding window
Bucketing
Ordered sets
Fraud and dispute signals
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample Answer
Requirements
  • Input: list of (timestamp, amount_cents) sorted by timestamp, plus T >= 0 and D >= 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, ...


Submit Your Answer
Markdown supported