Skip to content
LC-0933 Easy LeetCode

933. Number of Recent Calls

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 77% Topics: Design, Queue, Data Stream
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(1) on average
# Space: O(w), w means the size of the last milliseconds.

import collections


class RecentCounter(object):

    def __init__(self):
        self.__q = collections.deque()

    def ping(self, t):
        """
        :type t: int
        :rtype: int
        """
        self.__q.append(t)
        while self.__q[0] < t-3000:
            self.__q.popleft()
        return len(self.__q)

Solution from kamyu104/LeetCode-Solutions · MIT