Track Open Fraud Alerts Per Merchant With Constant-Time Max and Min

Last updated: November 29, 2026

Quick Overview

Implement a counter where inc(merchant) and dec(merchant) adjust a merchant's number of open fraud alerts, and max_key() and min_key() return a merchant with the most and the fewest open alerts, with every operation in O(1) time.

Capital One
Coding & Algorithms
Software Engineer
Capital One
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Implement a counter where inc(merchant) and dec(merchant) adjust a merchant's number of open fraud alerts, and max_key() and min_key() return a merchant with the most and the fewest open alerts, with every operation in O(1) time.

Capital One's fraud operations dashboards watch which merchants are accumulating open alerts right now, and counts move up and down constantly as alerts open and resolve. This Power Day data-structure question checks whether you can go beyond a heap (which gives O(log n) and struggles with decrements) to a linked list of count buckets.

What the Interviewer Expects
  • Explain why a heap or sorted map is not O(1)
  • Keep a doubly linked list of buckets ordered by count
  • Map each key to its bucket for O(1) lookup
  • Create and remove buckets lazily as counts change
  • Remove a key entirely when its count reaches zero
Key Topics to Cover
Data structure design
Doubly linked list
Hash maps
Amortized O(1)
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 return all merchants tied at the maximum, or the top 5?
  • How would you make this thread-safe without a single global lock?
  • How would you rebuild this state after a restart from an alert event log?
  • What changes if counts can jump by arbitrary amounts instead of plus or minus one?
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
  • inc(key): add 1, creating the key at 1 if new.
  • dec(key): subtract 1; at 0 the key disappears; unknown keys are ignored.
  • max_key() / min_key(): any key with the highest / lowest count, or...
High-Level Design

Keep buckets, one per distinct count, in a doubly linked list sorted by count between two sentinels. Each bucket holds the set of keys at that count, and a dict maps each key to its bucket. Because co...


Submit Your Answer
Markdown supported