-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cs
More file actions
37 lines (33 loc) · 751 Bytes
/
Solution.cs
File metadata and controls
37 lines (33 loc) · 751 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
public class RecentCounter
{
private readonly Queue<int> _requests;
public RecentCounter()
{
_requests = new Queue<int>();
}
public int Ping(int t)
{
_requests.Enqueue(t);
while (_requests.Count > 0 && _requests.Peek() < t - 3000)
{
_requests.Dequeue();
}
return _requests.Count;
}
}
public class Solution
{
public List<int> Execute(string[] actions, int[][] values)
{
RecentCounter counter = new();
List<int> ans = [];
for (int i = 0; i < actions.Length; i++)
{
if (actions[i] == "ping")
{
ans.Add(counter.Ping(values[i][0]));
}
}
return ans;
}
}