Five-Minute Hit Counter
Problem statement
Simulate a hit counter over a chronological operation sequence. Each operation has an integer type and timestamp:
- Type
0records one hit at that timestamp. - Type
1queries how many recorded hits occurred during the trailing300seconds.
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.
The problem statement continues
ProExamples
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.
FastPrep Pro
Reported in 1 Google interview this weekUnlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 2 more worked examples, explained
- Guided hints and editorial
- Run your code on real test cases
$8.25/month
$99 billed yearly — or $19 month-to-month. Cancel anytime.
Free plan — 2 of 2 free unlocks used this week