Tap here to switch tabs
Problem
Submissions

Problem: Design Hit Counter

Try to solve the Design Hit Counter problem.

Statement

Design a hit counter that tracks the number of hits received within the past 300300 seconds (i.e., the past 55 minutes).

Implement the HitCounter class:

  • HitCounter() Initializes the hit counter system.

  • void hit(int timestamp) Records a hit that occurred at the given timestamp (in seconds). Multiple hits may occur at the same timestamp.

  • int getHits(int timestamp) Returns the total number of hits received in the past 300300 seconds relative to timestamp (i.e., over the time interval from timestamp −299- 299 to timestamp, inclusive).

Constraints:

  • 1≤1 \le timestamp ≤2×109\le 2 \times 10^9

  • All calls to the system are made in chronological order (i.e., timestamp is monotonically increasing).

  • At most 300300 calls will be made in total to hit and getHits.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Design Hit Counter

Try to solve the Design Hit Counter problem.

Statement

Design a hit counter that tracks the number of hits received within the past 300300 seconds (i.e., the past 55 minutes).

Implement the HitCounter class:

  • HitCounter() Initializes the hit counter system.

  • void hit(int timestamp) Records a hit that occurred at the given timestamp (in seconds). Multiple hits may occur at the same timestamp.

  • int getHits(int timestamp) Returns the total number of hits received in the past 300300 seconds relative to timestamp (i.e., over the time interval from timestamp −299- 299 to timestamp, inclusive).

Constraints:

  • 1≤1 \le timestamp ≤2×109\le 2 \times 10^9

  • All calls to the system are made in chronological order (i.e., timestamp is monotonically increasing).

  • At most 300300 calls will be made in total to hit and getHits.