PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Amazon

Design rolling-window top-K click tracker

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's competency in streaming data processing, sliding-window aggregation, top-K frequency maintenance, deduplication under event lateness, and concurrent, horizontally scalable system design.

  • Medium
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Design rolling-window top-K click tracker

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Onsite

You receive a high-volume stream of click events (timestamp in ms, url). Implement a data structure with two operations: 1) record(event) inserts one event; 2) queryTopK(T, K, now) returns the K most-clicked URLs in the half-open interval (now − T, now], and queryUnique(T, now) returns the number of distinct URLs in that interval. Requirements: maintain near real-time results with efficient insert and eviction; target O(log K) or better per event for top-K maintenance; ensure memory stays bounded via time-based eviction. Handle out-of-order events with maximum lateness L and deduplicate by an event id for idempotency. Discuss the data structures you would use (e.g., time-bucketed sliding windows, hash maps for counts, heaps for top-K, deques for expirations), analyze time/space complexity, and explain how you would adapt the design for concurrency (multiple producer threads, lock contention minimization, atomicity of updates) and horizontal sharding.

Quick Answer: This question evaluates a candidate's competency in streaming data processing, sliding-window aggregation, top-K frequency maintenance, deduplication under event lateness, and concurrent, horizontally scalable system design.

Related Interview Questions

  • Count Connected Components in an Undirected Graph - Amazon (medium)
  • Find Unique Target-Sum Pairs - Amazon (easy)
  • Find Valid IP Addresses in Files - Amazon (medium)
  • Implement Optimal Bucket Batching - Amazon (hard)
  • Implement Cache and Rotate Matrix - Amazon (medium)
Amazon logo
Amazon
Jul 31, 2025, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
1
0

You receive a high-volume stream of click events (timestamp in ms, url). Implement a data structure with two operations:

  1. record(event) inserts one event;
  2. queryTopK(T, K, now) returns the K most-clicked URLs in the half-open interval (now − T, now], and queryUnique(T, now) returns the number of distinct URLs in that interval. Requirements: maintain near real-time results with efficient insert and eviction; target O(log K) or better per event for top-K maintenance; ensure memory stays bounded via time-based eviction. Handle out-of-order events with maximum lateness L and deduplicate by an event id for idempotency. Discuss the data structures you would use (e.g., time-bucketed sliding windows, hash maps for counts, heaps for top-K, deques for expirations), analyze time/space complexity, and explain how you would adapt the design for concurrency (multiple producer threads, lock contention minimization, atomicity of updates) and horizontal sharding.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Amazon•More Software Engineer•Amazon Software Engineer•Amazon Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.