PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

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.

Process hit/getHits operations for the inclusive interval [timestamp-299,timestamp]. Return outputs for getHits and None for hit.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: ([['hit',1], ['hit',2], ['getHits',300], ['getHits',301]],)

Expected Output: [None, None, 2, 1]

Explanation: Window moves.

Input: ([['getHits',1]],)

Expected Output: [0]

Explanation: No hits.

Input: ([['hit',5], ['hit',5], ['getHits',5]],)

Expected Output: [None, None, 2]

Explanation: Multiple hits same timestamp.

Hints

  1. Choose a representation that makes the requested operation direct.
  2. Handle empty inputs and boundary cases first.
Last updated: Jun 27, 2026

Loading coding console...

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.

Related Coding 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)