Daily Bucketed Rolling Spend for Fraud Features
Last updated: November 29, 2026
Quick Overview
Implement a structure that records card transactions per user and answers 'total spend in the last N days' using one bucket per calendar day, so memory stays bounded no matter how many transactions arrive.
Chalk
November 29, 20260
0
0 solved
Implement a structure that records card transactions per user and answers 'total spend in the last N days' using one bucket per calendar day, so memory stays bounded no matter how many transactions arrive.
Windowed aggregates like 30 or 90 day spend are among the most common features Chalk customers in lending and payments declare, and Chalk computes them with time buckets rather than raw scans. This screen checks clean bucketing arithmetic, inclusive and exclusive window edges, and eviction.
What the Interviewer Expects
- Converts timestamps to a day index with integer division
- Defines the window precisely: the current day plus the previous N - 1 days
- Evicts buckets that can never be read again
- Handles unknown users and empty windows by returning 0
- Explains the accuracy trade-off of day buckets versus exact sliding windows
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 get an exact trailing 24 hour sum while keeping bounded memory?
- How would you support several window sizes (1, 7, 30, 90 days) for the same feature efficiently?
- What changes if users live in different time zones and 'day' must be their local day?
- How would you handle a transaction that arrives two days late?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
add(entity, ts, amount) with ts in UTC seconds, and query(entity, now, days) returning the sum over the days most recent calendar days including today. Windows never exceed max_days, which l...
High-Level Design
Keep entity -> {day_index: total}. A day index is ts // 86400. A query with today T sums buckets with T - days < d <= T. On read we also drop buckets at or below T - max_days, so each user h...