PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Decagon

Design Sliding-Window Average Tracker

Last updated: Mar 29, 2026

Quick Overview

This question evaluates design and implementation of a time-windowed tracking data structure, focusing on streaming aggregation, handling monotonic timestamps, efficient updates, and time/space trade-offs.

  • medium
  • Decagon
  • Coding & Algorithms
  • Software Engineer

Design Sliding-Window Average Tracker

Company: Decagon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Design a class that tracks records in a sliding time window. Implement the following API: - `init(time_window)`: initialize the object with a window size. - `insert(record_id, value, timestamp)`: insert a new record. - `get_avg(timestamp)`: return the average `value` of all records whose timestamps fall within the most recent `time_window` ending at `timestamp`. Assumptions and requirements: - `record_id` is unique for each inserted record. - Timestamps are integers. - Calls to `insert(...)` and `get_avg(...)` are made with non-decreasing timestamps. - A record is considered active at time `t` if its timestamp is in the interval `[t - time_window + 1, t]`. - If no records are active in the window, return `0`. - The implementation should be optimized for the monotonic-timestamp constraint. Follow-up: - Support `update(record_id, new_timestamp)`, which changes the timestamp of an existing record while keeping its original value unchanged. - Explain how your design would change if inserts and queries could arrive with out-of-order timestamps.

Quick Answer: This question evaluates design and implementation of a time-windowed tracking data structure, focusing on streaming aggregation, handling monotonic timestamps, efficient updates, and time/space trade-offs.

Related Interview Questions

  • Implement a Recipe Cart - Decagon (medium)
  • Implement a CSAT Sliding Window Tracker - Decagon (easy)
  • Enumerate 4x4 Tic-Tac-Toe Games - Decagon (medium)
  • Design rolling-window conversation score tracker - Decagon (easy)
  • Compute exclusive CPU time from nested logs - Decagon (medium)
Decagon logo
Decagon
Jan 31, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
7
0
Loading...

Design a class that tracks records in a sliding time window.

Implement the following API:

  • init(time_window) : initialize the object with a window size.
  • insert(record_id, value, timestamp) : insert a new record.
  • get_avg(timestamp) : return the average value of all records whose timestamps fall within the most recent time_window ending at timestamp .

Assumptions and requirements:

  • record_id is unique for each inserted record.
  • Timestamps are integers.
  • Calls to insert(...) and get_avg(...) are made with non-decreasing timestamps.
  • A record is considered active at time t if its timestamp is in the interval [t - time_window + 1, t] .
  • If no records are active in the window, return 0 .
  • The implementation should be optimized for the monotonic-timestamp constraint.

Follow-up:

  • Support update(record_id, new_timestamp) , which changes the timestamp of an existing record while keeping its original value unchanged.
  • Explain how your design would change if inserts and queries could arrive with out-of-order timestamps.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

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

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