Rolling Median Anomaly Check on Card Transaction Amounts
Last updated: November 29, 2026
Quick Overview
For a customer's sequence of transaction amounts, flag every index i (i >= k) where amounts[i] is greater than factor times the median of the previous k amounts. Do it faster than re-sorting each window.
N26
November 29, 20260
0
0 solved
For a customer's sequence of transaction amounts, flag every index i (i >= k) where amounts[i] is greater than factor times the median of the previous k amounts. Do it faster than re-sorting each window.
N26 shows real-time push notifications for every card payment and runs risk checks on the same path, so cheap per-customer baselines matter. The interviewer is looking for the two-heap median with deletion of the element leaving the window, and for a correct, bug-free implementation of lazy deletion.
What the Interviewer Expects
- Explain why median beats mean for spending baselines (robust to one big purchase)
- Use two heaps to get the median in O(1) and updates in O(log k)
- Handle removals with lazy deletion and keep logical sizes separate from heap lengths
- Check the current value against the window before inserting it
- Verify against a brute-force version on random inputs
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 do this with a sorted container instead of heaps, and what are the trade-offs?
- How would you keep a per-customer median for millions of customers in a streaming system?
- Would an approximate median (for example a t-digest) be acceptable here?
- How would you use a time window (last 30 days) instead of a count window?
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 positive amounts, window size k >= 1, a multiplier factor. For each i >= k, compare amounts[i] to factor * median(amounts[i-k:i]). The current amount is not part of its own ba...
High-Level Design
Keep a max-heap low for the smaller half and a min-heap high for the larger half, with len(low) equal to or one more than len(high). Median is low top, or the average of both tops. Python he...