FastPrepImplement Hit Counter
Problems/Implement Hit Counter

Implement Hit Counter

Apple logoApple● MediumFULLTIMEPHONE SCREENONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: An Apple phone-screen report asks for hit(timestamp) and getHits(timestamp) over a trailing five-minute window. This practice version uses nondecreasing positive timestamps and counts hits in the inclusive interval from timestamp - 299 through timestamp.

Process chronological hit and getHits operations. A query returns the number of hits in the inclusive interval from timestamp - 299 through timestamp. Return "null" for a hit and the decimal count for a query.

Function

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

Examples

Example 1

operations = ["hit","hit","hit","getHits","hit","getHits"]timestamps = [1,2,3,4,300,301]return = ["null","null","null","3","null","3"]

At time 301, the hit at time 1 has expired but the other three remain.

Constraints

  • Operation and timestamp arrays have equal non-zero length.
  • Timestamps are positive and non-decreasing.
  • There are at most 100000 operations.

More Apple problems

  • Evaluate DivisionPHONE SCREEN · Seen Nov 2026
  • Reverse a Linked ListPHONE SCREEN · Seen Nov 2026
  • Validate a BST with a Custom ComparisonPHONE SCREEN · Seen Nov 2026
All Apple interview questionsSee Apple hiring insights
Saved
class Solution {
    public String[] runHitCounter(String[] operations, int[] timestamps) {
      // Write your code here.
    }

}
Checking account…