PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/StackAdapt

Design a time-windowed key-value store

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's ability to design efficient data structures and algorithms for a time-windowed key-value store, focusing on expiration handling, update semantics, and maintaining aggregate metrics under memory constraints.

  • easy
  • StackAdapt
  • Coding & Algorithms
  • Software Engineer

Design a time-windowed key-value store

Company: StackAdapt

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

Implement a **time-windowed key-value store** ("Windowed Map") that receives key/value updates at irregular times and only keeps entries from the **most recent window** of length `windowMs`. - Each key has a **value** (assume numeric, e.g., `double` or `long`) and a **timestamp** (milliseconds since epoch, e.g., from `System.currentTimeMillis()` or an injected clock). - Data older than `now - windowMs` is **expired** and must be treated as invisible to the user and eligible for eviction. - You may assume that at any moment, all **currently valid** entries fit in memory, but the entire lifetime of all entries does not (so you must expire/evict old data). - Single-threaded only. Provide these APIs and aim to make them as efficient as possible: 1) `Get(key)`: if `key` exists and is not expired, return its value; otherwise return `null` (or throw). - `Get` does **not** update the timestamp. 2) `Put(key, value)`: insert or update the key/value. - Each `Put` updates that key’s timestamp to `now`. 3) `GetAverage()`: return the average of all **currently valid** values in the window. Example: - `Put("a", 10)` at `t=0` - `Put("b", 20)` at `t=1` - `GetAverage()` returns `15.0` - After waiting 11 seconds (for a 10-second window): - `Get("a")` returns `null` (expired) - `GetAverage()` only considers still-valid keys. Discuss the data structures you would use and the time complexity targets (e.g., O(1) average or worst-case, and what is or isn’t achievable).

Quick Answer: This question evaluates a candidate's ability to design efficient data structures and algorithms for a time-windowed key-value store, focusing on expiration handling, update semantics, and maintaining aggregate metrics under memory constraints.

Related Interview Questions

  • Analyze time complexity for dictionary operations - StackAdapt (Medium)
StackAdapt logo
StackAdapt
Mar 4, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
6
0

Implement a time-windowed key-value store ("Windowed Map") that receives key/value updates at irregular times and only keeps entries from the most recent window of length windowMs.

  • Each key has a value (assume numeric, e.g., double or long ) and a timestamp (milliseconds since epoch, e.g., from System.currentTimeMillis() or an injected clock).
  • Data older than now - windowMs is expired and must be treated as invisible to the user and eligible for eviction.
  • You may assume that at any moment, all currently valid entries fit in memory, but the entire lifetime of all entries does not (so you must expire/evict old data).
  • Single-threaded only.

Provide these APIs and aim to make them as efficient as possible:

  1. Get(key) : if key exists and is not expired, return its value; otherwise return null (or throw).
    • Get does not update the timestamp.
  2. Put(key, value) : insert or update the key/value.
    • Each Put updates that key’s timestamp to now .
  3. GetAverage() : return the average of all currently valid values in the window.

Example:

  • Put("a", 10) at t=0
  • Put("b", 20) at t=1
  • GetAverage() returns 15.0
  • After waiting 11 seconds (for a 10-second window):
    • Get("a") returns null (expired)
    • GetAverage() only considers still-valid keys.

Discuss the data structures you would use and the time complexity targets (e.g., O(1) average or worst-case, and what is or isn’t achievable).

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

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

Master your tech interviews with 8,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.