PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Uber

Implement an expiring counter class

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's competency in implementing a sliding-window expiring counter, testing knowledge of streaming algorithms, data structures for time-series aggregation, amortized time complexity, and memory-efficient design in the Coding & Algorithms domain.

  • medium
  • Uber
  • Coding & Algorithms
  • Software Engineer

Implement an expiring counter class

Company: Uber

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Expiring Counter (sliding time window) Design and implement an **expiring counter** that counts events in a recent time window. ### Requirements - You are given a fixed window size `W` in **seconds** when constructing the counter. - Support two operations: 1. `inc(timestamp, delta=1)`: record `delta` events occurring at integer time `timestamp` (in seconds). 2. `get(timestamp) -> int`: return the total number of events recorded in the **inclusive** time range: \[ [timestamp - W + 1,\; timestamp] \] ### Assumptions / clarifications (state and use in your solution) - Timestamps are integer seconds. - You may assume calls arrive with **non-decreasing timestamps** (typical for streaming counters). If you choose not to assume this, explain how you would handle out-of-order inputs. ### Constraints / goals - Aim for efficient time and space usage: roughly **O(1) amortized** per operation and memory proportional to the window. ### Follow-up If `inc()` can be called up to **1,000,000 times per second**, how would you modify the design to reduce memory and CPU overhead (e.g., batching/aggregating within each second)?

Quick Answer: This question evaluates a candidate's competency in implementing a sliding-window expiring counter, testing knowledge of streaming algorithms, data structures for time-series aggregation, amortized time complexity, and memory-efficient design in the Coding & Algorithms domain.

Related Interview Questions

  • Maximize Throughput and Count Trigger Components - Uber (medium)
  • Replace Dashes With Nearest Letters - Uber (medium)
  • Find Earliest Column With One - Uber (easy)
  • Solve Wonderful Strings and Grid Queries - Uber (hard)
  • Count Islands After Land Additions - Uber (medium)
Uber logo
Uber
Jan 6, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
9
0
Loading...

Expiring Counter (sliding time window)

Design and implement an expiring counter that counts events in a recent time window.

Requirements

  • You are given a fixed window size W in seconds when constructing the counter.
  • Support two operations:
    1. inc(timestamp, delta=1) : record delta events occurring at integer time timestamp (in seconds).
    2. get(timestamp) -> int : return the total number of events recorded in the inclusive time range:

[timestamp−W+1,  timestamp][timestamp - W + 1,\; timestamp][timestamp−W+1,timestamp]

Assumptions / clarifications (state and use in your solution)

  • Timestamps are integer seconds.
  • You may assume calls arrive with non-decreasing timestamps (typical for streaming counters). If you choose not to assume this, explain how you would handle out-of-order inputs.

Constraints / goals

  • Aim for efficient time and space usage: roughly O(1) amortized per operation and memory proportional to the window.

Follow-up

If inc() can be called up to 1,000,000 times per second, how would you modify the design to reduce memory and CPU overhead (e.g., batching/aggregating within each second)?

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Uber•More Software Engineer•Uber Software Engineer•Uber 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.