PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Google

Design a rolling hit counter API

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency with data structures for time-window aggregation and understanding of time/space trade-offs when counting events within a rolling interval.

  • medium
  • Google
  • Coding & Algorithms
  • Software Engineer

Design a rolling hit counter API

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

### Rolling hit counter (time/space optimized) Design a data structure that records events (“hits”) and can return how many hits happened in the most recent **300 seconds**. Implement two operations: - `hit(t)`: record a hit at integer timestamp `t` (seconds). - `getHits(t)`: return the number of hits with timestamps in the inclusive range **[t-299, t]**. #### Assumptions / requirements - Timestamps are non-decreasing across calls. - Multiple hits may occur at the same timestamp. - You should optimize for time and space (avoid storing every hit individually if many occur at the same second). #### Output Return correct counts for each `getHits` query. #### Complexity discussion Be prepared to justify the time/space complexity of your approach and how it behaves under very high hit volume.

Quick Answer: This question evaluates proficiency with data structures for time-window aggregation and understanding of time/space trade-offs when counting events within a rolling interval.

Related Interview Questions

  • Find Containing Range - Google (medium)
  • Rearrange Tasks With Cooldown - Google (medium)
  • Solve Three Array and Matrix Path Problems - Google (medium)
  • Consolidate On-Call Rotation Segments - Google (medium)
  • Solve Flower Placement and Directory Deletion - Google (medium)
Google logo
Google
Jan 6, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
6
0
Loading...

Rolling hit counter (time/space optimized)

Design a data structure that records events (“hits”) and can return how many hits happened in the most recent 300 seconds.

Implement two operations:

  • hit(t) : record a hit at integer timestamp t (seconds).
  • getHits(t) : return the number of hits with timestamps in the inclusive range [t-299, t] .

Assumptions / requirements

  • Timestamps are non-decreasing across calls.
  • Multiple hits may occur at the same timestamp.
  • You should optimize for time and space (avoid storing every hit individually if many occur at the same second).

Output

Return correct counts for each getHits query.

Complexity discussion

Be prepared to justify the time/space complexity of your approach and how it behaves under very high hit volume.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

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