File tree Expand file tree Collapse file tree 1 file changed +0
-37
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +0
-37
lines changed Original file line number Diff line number Diff line change 1
1
package com .fishercoder .solutions ;
2
- /**
3
- * 362. Design Hit Counter
4
- *
5
- * Design a hit counter which counts the number of hits received in the past 5 minutes.
6
-
7
- Each function accepts a timestamp parameter (in seconds granularity) and you may assume
8
- that calls are being made to the system in chronological order (ie, the timestamp is monotonically increasing).
9
- You may assume that the earliest timestamp starts at 1.
10
-
11
- It is possible that several hits arrive roughly at the same time.
12
-
13
- Example:
14
- HitCounter counter = new HitCounter();
15
-
16
- // hit at timestamp 1.
17
- counter.hit(1);
18
-
19
- // hit at timestamp 2.
20
- counter.hit(2);
21
-
22
- // hit at timestamp 3.
23
- counter.hit(3);
24
-
25
- // get hits at timestamp 4, should return 3.
26
- counter.getHits(4);
27
-
28
- // hit at timestamp 300.
29
- counter.hit(300);
30
-
31
- // get hits at timestamp 300, should return 4.
32
- counter.getHits(300);
33
-
34
- // get hits at timestamp 301, should return 3.
35
- counter.getHits(301);
36
- Follow up:
37
- What if the number of hits per second could be very large? Does your design scale?
38
- */
39
2
40
3
public class _362 {
41
4
You can’t perform that action at this time.
0 commit comments