MMyntra·DSASDE-1DSA Round
Top 5 Trending Products in the Last 7 Days
Problem
Given a stream of purchase events (productId, timestamp), at any point return the top 5 most purchased products in the last 7 days (sliding window).
Example
events = [(P1,t1),(P2,t2),(P1,t3),...]
query at t_now → top 5 products by count in [t_now-7days, t_now]
Constraints
- Up to 10^7 events
- Up to 10^6 unique products
- Queries happen in real time
Approaches
- Offline batch: aggregate per day, maintain 7-day rolling sum
- Online: bucketed counters (1 bucket per hour) + min-heap for top-k
Myntra follow-up
Extend to return trending products per category and per city simultaneously.
added 1 week ago