Number of Recent Calls

Problem Summary

(Write in your own words, not copied from LeetCode. This forces comprehension.)

Why This Works

(Explain the core reason the solution is correct.)

Main Concepts Used

(Mark the CS concepts or algorithms used.)

Time & Space Complexity

Code

class RecentCounter:
    rangeInMs = 3000

    def __init__(self):
        self.queue = deque()

    def ping(self, t: int) -> int:
        self.queue.append(t)
        rangeStart = t - self.rangeInMs

        while self.queue and self.queue[0] < rangeStart:
            self.queue.popleft()

        return len(self.queue)

Common Mistakes / Things I Got Stuck On