public class RecentCounter { Queue<int> Q; public RecentCounter() { Q = new Queue<int>(); Q.Clear(); } public int Ping(int t) { Q.Enqueue(t); while (Q.Peek() < t - 3000) { Q.Dequeue(); } return Q.Count; } }