Flag Accounts With Repeated Declines in a Rolling Window

Last updated: November 29, 2026

Quick Overview

Given a time-ordered stream of authorization events (timestamp, account, approved), return every account that reaches at least `threshold` declined authorizations within any rolling window of `window` seconds, in the order they were first flagged.

Capital One
Coding & Algorithms
Software Engineer
Capital One
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Medium

0

0

0 solved


Given a time-ordered stream of authorization events (timestamp, account, approved), return every account that reaches at least `threshold` declined authorizations within any rolling window of `window` seconds, in the order they were first flagged.

Repeated declines in a short span are a classic card-testing signal that Capital One's fraud systems watch for. On the CodeSignal-style assessment this checks whether you keep a per-key sliding window with a deque rather than rescanning history for every event, and whether you get the window boundary exactly right.

What the Interviewer Expects
  • Maintain a separate window per account
  • Evict timestamps that fall outside the window before counting
  • Ignore approved events when counting declines
  • Flag each account only once and keep first-flag order
  • State the inclusive or exclusive boundary explicitly
Key Topics to Cover
Sliding window
Deque
Hash map of queues
Streaming fraud 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 do you bound memory when there are tens of millions of accounts and most go quiet?
  • How would you handle events that arrive slightly out of order?
  • How would you change this to count declines per merchant and per card together?
  • What if the threshold should apply to the decline rate rather than the raw count?
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
  • Events arrive sorted by timestamp in seconds.
  • A window ending at time t covers timestamps strictly greater than t - window, so two declines exactly window seconds apart do not share a window...
High-Level Design

Keep account -> deque of decline timestamps. On each decline, append the new timestamp, pop from the left while the oldest timestamp is at or before t - window, then compare the deque length to th...


Submit Your Answer
Markdown supported