FastPrepCount Hits in the Last Five Minutes
Problems/Count Hits in the Last Five Minutes

Count Hits in the Last Five Minutes

Decagon logoDecagon● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Decagon phone screen. The report uses a short label for the exercise. The requester's clarification showed it is the standard hit-counter task. The core is calls in time order, repeated hits, and the count over the last 300 seconds. We chose the finite limits and how a batch returns its answers. Our version is about 95% the same as the reported question.

Process a sequence of calls to an initially empty hit counter. Each operations[i] is "hit" or "getHits", made at second timestamps[i]. Calls are in nondecreasing timestamp order.

A hit records one event. A getHits call at second t returns the number of previously recorded hits in (t - 300, t]. A hit exactly 300 seconds old is excluded. Several hits at the same second count separately.

Return the query results in call order. Recording a hit produces no output; calls at an equal timestamp still execute in array order.

Function

processHitCounter(operations: String[], timestamps: int[]) → int[]

Examples

Example 1

operations = ["hit","hit","getHits","hit","getHits","getHits"]timestamps = [10,10,309,309,309,310]return = [2,3,1]

Both hits at second 10 remain at second 309. A new hit at 309 raises the count to 3. At second 310, the two hits at 10 have age 300 and expire, leaving 1.

Example 2

operations = ["getHits","hit","getHits","getHits"]timestamps = [5,5,5,305]return = [0,1,0]

The counter starts empty. A hit at second 5 is visible to a later query at the same second, but expires at second 305.

Example 3

operations = ["hit","hit","hit","getHits","getHits"]timestamps = [1,150,300,300,450]return = [3,1]

At second 300 all three hits are in the window. At second 450 the window is (150,450], so only the hit at 300 remains.

Constraints

  • For this exercise, assume 1 <= operations.length == timestamps.length <= 1000.
  • Every operation is exactly "hit" or "getHits", and at least one is "getHits".
  • 1 <= timestamps[i] <= 10^9; timestamps are nondecreasing.

More Decagon Phone Screen questions

  • Count Complete Tic-Tac-Toe GamesPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Rolling CSAT TrackerPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Batch API Requests with Retry DelaysPHONE SCREEN · Seen Sep 2026
  • Recipe Cart with Undo and RedoPHONE SCREEN · Seen Sep 2026
  • Recipe Shopping Cart DiscountsPHONE SCREEN · Seen Aug 2026
  • Versioned Recipe Shopping CartPHONE SCREEN · Seen Jul 2026
  • Nested Recipe Cart TransactionsPHONE SCREEN · Seen Jul 2026
  • Exclusive Function Execution TimePHONE SCREEN · Seen Mar 2026
  • Largest Rectangle in a HistogramPHONE SCREEN · Seen Dec 2024

Similar questions at other companies

  • Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
  • VIP and Regular Service SchedulerIntuit · PHONE SCREENIntuit interview questions
  • Implement a FIFO QueueByteDance · PHONE SCREENByteDance interview questions
  • Stateful Paginated Fetch NLyft · PHONE SCREENLyft interview questions
  • Music Player Operation SequenceAtlassian · PHONE SCREENAtlassian interview questions
  • Ring Buffer OperationsApplied Intuition · PHONE SCREENApplied Intuition interview questions
  • Recent Event Stream QueriesSnowflake · PHONE SCREENSnowflake interview questions
  • Machine Message RouterOpenAI · PHONE SCREENOpenAI interview questions
  • Article Vote TrackerRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Completions API Rate LimiterCursor · PHONE SCREENCursor interview questions

Decagon interview experiences

  • Decagon Experienced SWE Phone Screen: 1 Experience
  • Decagon New Grad SWE Interviews: 1 Experience
All Decagon interview questionsSee Decagon hiring insights
Saved
class Solution {
    public int[] processHitCounter(String[] operations, int[] timestamps) {
        return new int[0];
    }
}
Checking account…