FastPrepDesign Hit Counter
Problems/Design Hit Counter

Design Hit Counter

Charta Health logoCharta Health● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: For a Senior Software Engineer role at Charta Health, the candidate got a second virtual coding round, probably because the first one went poorly. The task was the well-known Design Hit Counter problem, named only by a link.

The report gives no rules, limits or examples. This version uses the usual ones. A call at second t counts hits from t - 299 through t, many hits can share a second, and the times never go down. You get the hit and getHits calls as a list of operations instead of a class.

Our version is about 90% the same as the reported question.

Build a hit counter for a website. It records hits and can tell how many hits happened in the last five minutes. Time is measured in whole seconds.

The calls come as two arrays of the same length. Call i is operations[i] at second timestamps[i], and you handle the calls in order:

  • "hit": one hit happens at that second. Several hits can happen in the same second.
  • "getHits": report how many hits happened in the last 300 seconds. For a call at second t, count every hit from second t - 299 through second t, both included.

A "getHits" call only counts hits from calls that come before it in the list. A hit listed after it does not count, even when it has the same second.

Return an array with one count for each "getHits" call, in the order of the calls. A "hit" call adds nothing to the array.

Function

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

Examples

Example 1

operations = ["hit","hit","getHits","hit","getHits","getHits"]timestamps = [10,20,25,309,309,320]return = [2,3,1]
  • At second 25, the window is seconds 1 through 25. It holds the hits at 10 and 20, so the count is 2.
  • At second 309, the window is 10 through 309. It holds the hits at 10, 20 and 309, so the count is 3.
  • At second 320, the window is 21 through 320. The hits at 10 and 20 are too old, so the count is 1.

Example 2

operations = ["hit","getHits","hit","hit","getHits"]timestamps = [5,5,5,5,304]return = [1,3]
  • The first "getHits" at second 5 sees only the one hit listed before it. The two hits listed after it come later, so the count is 1.
  • At second 304, the window is 5 through 304, so all three hits at second 5 still count. The count is 3.

Example 3

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

The first call comes before any hit, so its count is 0. Then one hit happens at second 2000000000, and the last call counts it, so its count is 1.

Constraints

  • 1 <= operations.length <= 10^4
  • timestamps.length == operations.length
  • Each operations[i] is "hit" or "getHits".
  • 1 <= timestamps[i] <= 2 * 10^9
  • timestamps never goes down: timestamps[i] <= timestamps[i + 1].

More Charta Health interview questions

  • Insert Delete GetRandom O(1)PHONE SCREEN · Seen Nov 2026
  • Integers With Multiple Sum of Two CubesPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Concurrent Token-Bucket Rate LimiterPHONE SCREEN · Seen Sep 2026
  • Inorder Successor in a Binary Search TreeONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • 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
  • Zigzag Iterator Over Two ListsGoogle · PHONE SCREENGoogle interview questions
  • Bounded Circular QueueDatadog · PHONE SCREENDatadog interview questions
  • Round-Robin Iterator over IteratorsBridge · ONSITE INTERVIEWBridge interview questions
  • Design Hit CounterNutanix · ONSITE INTERVIEWNutanix interview questions
All Charta Health interview questionsSee Charta Health hiring insights
Saved
class Solution {
    public int[] hitCounter(String[] operations, int[] timestamps) {
        // Write your code here.
    }
}
Checking account…