FastPrepFive-Minute Hit Counter
Problems/Five-Minute Hit Counter

Five-Minute Hit Counter

Google logoGoogle● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks for record(timestamp) and getHits(timestamp) over the last 300 seconds. It then discusses any window size and very large scale. It does not give the finite interface or the exact boundary rule. Our version is about 96% the same as the reported question.

Special thanks: 🌷 A special thank you to our lovely, amazing frenz who shared that this question appeared again on October 5, 2026! ദ്ദി(˵ •̀ ᴗ - ˵ ) ✧ 💜

Simulate a hit counter over a chronological operation sequence. Each operation has an integer type and timestamp:

  • Type 0 records one hit at that timestamp.
  • Type 1 queries how many recorded hits occurred during the trailing 300 seconds.

For a query at timestamp t, count hits whose timestamps lie in the half-open interval (t - 300, t]. Multiple hits at the same timestamp count separately. Return the query results in encounter order.

Interview follow-ups

  • Arbitrary windows: discuss how the structure changes when a query supplies any positive window length k instead of the fixed value 300.
  • Distributed scale: discuss how to aggregate timestamp buckets across shards when one machine cannot retain or process the event volume.

The function you write uses only the fixed 300-second rule above.

Function

countRecentHits(operationTypes: int[], timestamps: int[]) → int[]

Examples

Example 1

operationTypes = [0,0,0,1,1]timestamps = [1,2,3,4,300]return = [3,3]

At timestamp 4, all three hits are recent. At timestamp 300, the hit at timestamp 1 is still inside (0, 300], so the count remains 3.

Example 2

operationTypes = [0,0,1,0,1]timestamps = [1,1,1,300,301]return = [2,1]

The first query counts both hits at timestamp 1. At timestamp 301, those hits lie exactly on the excluded left boundary, while the hit at timestamp 300 remains.

Example 3

operationTypes = [1,0,1]timestamps = [100,400,400]return = [0,1]

The first query occurs before any hit. The hit recorded at timestamp 400 is immediately visible to the following query at the same timestamp.

Constraints

  • 1 <= operationTypes.length == timestamps.length <= 200000.
  • Every operation type is 0 or 1.
  • 1 <= timestamps[i] <= 10^9.
  • timestamps is nondecreasing.

More Google Onsite Interview questions

  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Ring Buffer OperationsAmazon · ONSITE INTERVIEW
  • Recent Hit CounterAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
  • Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
  • Implement a FIFO QueueByteDance · PHONE SCREENByteDance interview questions
  • Stateful Paginated Fetch NLyft · PHONE SCREENLyft interview questions
  • Music Player Operation SequenceAtlassian · PHONE SCREENAtlassian interview questions
  • Machine Message RouterOpenAI · PHONE SCREENOpenAI interview questions
  • Implement a FIFO QueueOptiver · PHONE SCREENOptiver interview questions
  • Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
  • Round-Robin Iterator over IteratorsBridge · ONSITE INTERVIEWBridge interview questions

Interview reports that mention this question

  • Google Software Engineer Onsite Questions: 10 Experiences

Google interview experiences

  • Google interviews · November 2026
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int[] countRecentHits(int[] operationTypes, int[] timestamps) {
        // Write your code here.
    }
}
Checking account…