Login using Social Account
     Continue with GoogleLogin using your credentials
You have a RecentCounter class that counts the number of recent requests within a certain time frame.
Implement the RecentCounter class:
RecentCounter() Initializes the counter with zero recent requests.ping(t: int) Adds a new request at a time t, where t represents some time in milliseconds and returns the number of requests that have happened in the past 3000 milliseconds (including the new request). Specifically, return the number of requests that have happened in the inclusive range [t - 3000, t].It is guaranteed that every call to ping uses a strictly larger value of t than the previous call.
Example:
Input: [1, 100, 3001, 3002]
Output: [1, 2, 3, 3]
Explanation:
recentCounter = RecentCounter();
recentCounter.ping(1);     // requests = [1], range is [-2999,1], return 1
recentCounter.ping(100);   // requests = [1, 100], range is [-2900,100], return 2
recentCounter.ping(3001);  // requests = [1, 100, 3001], range is [1,3001], return 3
recentCounter.ping(3002);  // requests = [1, 100, 3001, 3002], range is [2,3002], return 3
Constraints:
t <= 10^9(10 to the power 9)t.RecentCountertCopy the below code and paste it in the right side coding panel, and complete the ping method in RecentCounter class
class RecentCounter:
   def __init__(self):
       pass
   def ping(self, t: int) -> int:
       # your code
def recent_counter_main(calls: int) -> list:
    output_list = []
    rc = RecentCounter()
    for call in calls:
        output_list.append(rc.ping(call))
    return output_list
 
            Taking you to the next exercise in seconds...
Want to create exercises like this yourself? Click here.
No hints are availble for this assesment
Note - Having trouble with the assessment engine? Follow the steps listed here
Loading comments...