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).

Input / Output

  • Input: a stream of (productId, timestamp) events, plus point-in-time top-5 queries.
  • Output: the 5 products with the highest purchase count in [t_now − 7 days, t_now].

Constraints

  • Up to 10^7 events.
  • Up to 10^6 unique products.
  • Queries happen in real time.

Example

  • events = [(P1,t1),(P2,t2),(P1,t3),...]; query at t_now → top 5 products by count in [t_now−7days, t_now].
added …
LeaderboardSalaryAccount
Top 5 Trending Products in the Last 7 Days · 2dbi