typedef struct { int arr[10001]; int n; int start; } RecentCounter; RecentCounter* recentCounterCreate() { RecentCounter* obj = (RecentCounter*)calloc(sizeof(RecentCounter),1); obj->n = obj->start = 0; return obj; } int recentCounterPing(RecentCounter* obj, int t) { obj->arr[obj->n++] = t; for (int i=obj->start; i<obj->n; i++) { if (obj->arr[i] >= t-3000) { obj->start = i; return obj->n-i; } } return 0; } void recentCounterFree(RecentCounter* obj) { free(obj); }