> ## Content Index
> Fetch the complete content index at: https://andybase.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# 933 Number of Recent Calls
- URL: https://andybase.com/933-number-of-recent-calls/
- Published: 2018-11-08T21:57:34.000Z
- Updated: 2018-11-08T21:57:34.000Z
- Author: andy
- Tags: leetcode, contest, #Migrated-1784083136856, #wp, #wp-post, #Import 2026-07-15 02:38

link: [Number of Recent Calls](https://leetcode.com/problems/number-of-recent-calls/?ref=andybase.com)

## Thought

Question ask for numbers of calls in 3000\. So sliding windows is my choice here - it will move and drop calls earlier than 3000 - which I don't care, and keep tracing incoming calls.

## Code

```
class RecentCounter:

    def __init__(self):
        self.t = collections.deque()
        self.cnt = 0

    def ping(self, t):
        """
        :type t: int
        :rtype: int
        """
        while self.t and self.t[0] < t - 3000:
            self.t.popleft()
            self.cnt -= 1
        self.t.append(t)
        self.cnt += 1
        return self.cnt
```

## Runtime

Time: O(n)  
Space: O(n)