PracHub
QuestionsPremiumLearningGuidesInterview PrepCoaches
|Home/Coding & Algorithms/Roblox

Implement recent-requests counter

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's ability to design efficient in-memory data structures and manage time-windowed event counting, testing algorithmic reasoning and performance optimization for high-throughput services.

  • easy
  • Roblox
  • Coding & Algorithms
  • Machine Learning Engineer

Implement recent-requests counter

Company: Roblox

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

You are designing an in-memory component for a web service that needs to track how many requests ("hits") it has received in the last 5 minutes. Implement a class that supports two operations: - `void hit(int timestamp)` Records a hit at time `timestamp` (in seconds). You may assume: - Timestamps are given in **strictly increasing** order across all calls. - There may be multiple hits at the same `timestamp`. - `int getHits(int timestamp)` Returns the number of hits that occurred in the **past 5 minutes** (i.e., in the inclusive interval `[timestamp - 299, timestamp]`), where `timestamp` is also specified in seconds and is >= any previous timestamp seen. Additional details and constraints: - You only need to store data for the last 5 minutes at any point in time; older data should be discarded or ignored. - Optimize for many calls to `hit` and `getHits` per second. - Aim for better than O(n) per query, where n is the total number of hits ever seen. Define the class interface and implement the methods `hit` and `getHits`.

Quick Answer: This question evaluates a candidate's ability to design efficient in-memory data structures and manage time-windowed event counting, testing algorithmic reasoning and performance optimization for high-throughput services.

Related Interview Questions

  • Find Windows Containing a Target - Roblox (medium)
  • Implement Sliding-Window Rate Limiter - Roblox (medium)
  • Find target-heavy sliding windows - Roblox (medium)
  • Find most frequent call path in logs - Roblox (medium)
  • Track Highest-Earning Experience - Roblox (medium)
Roblox logo
Roblox
Dec 8, 2025, 7:56 PM
Machine Learning Engineer
Technical Screen
Coding & Algorithms
9
0

You are designing an in-memory component for a web service that needs to track how many requests ("hits") it has received in the last 5 minutes.

Implement a class that supports two operations:

  • void hit(int timestamp)
    Records a hit at time timestamp (in seconds).
    You may assume:
    • Timestamps are given in strictly increasing order across all calls.
    • There may be multiple hits at the same timestamp .
  • int getHits(int timestamp)
    Returns the number of hits that occurred in the past 5 minutes (i.e., in the inclusive interval [timestamp - 299, timestamp] ), where timestamp is also specified in seconds and is >= any previous timestamp seen.

Additional details and constraints:

  • You only need to store data for the last 5 minutes at any point in time; older data should be discarded or ignored.
  • Optimize for many calls to hit and getHits per second.
  • Aim for better than O(n) per query, where n is the total number of hits ever seen.

Define the class interface and implement the methods hit and getHits.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Roblox•More Machine Learning Engineer•Roblox Machine Learning Engineer•Roblox Coding & Algorithms•Machine Learning 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.