`{"id":"41837b53-12f3-4b3f-a73c-5894120d14c2","name":"Number Of Recent Calls","description":"You have a RecentCounter class which counts the number of recent requests within a certain time frame.\r\n\r\nImplement the RecentCounter class:\r\n1. RecentCounter() Initializes the counter with zero recent requests.\r\n2. int ping(int t) Adds a new request at time t, where t represents some time in milliseconds, and returns the number of requests that has 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].\r\n\r\nIt is guaranteed that every call to ping uses a strictly larger value of t than the previous call.\r\n","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1. 1 &lt;= t &lt;= 10^9\r\n2. Each test case will call ping with strictly increasing values of t.","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\nclass RecentCounter {\n public:\n // write your code here\n int ping(int t){\n return 0;\n }\n };\n\nint main(){ \n RecentCounter obj ;\n string input;\n while(getline(cin, input)){\n int data = stoi(input);\n int result = obj.ping(data);\n cout<< result<<endl;\n }\n \n return 0;\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n public static class RecentCounter {\r\n\r\n public RecentCounter() {\r\n }\r\n\r\n public int ping(int t) {\r\n return 0;\r\n }\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n RecentCounter obj = new RecentCounter();\r\n\r\n while (read.ready()) {\r\n int val = Integer.parseInt(read.readLine());\r\n int ans = obj.ping(val);\r\n System.out.println(ans);\r\n }\r\n\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"1\r\n100\r\n3001\r\n3002","sampleOutput":"1\r\n2\r\n3\r\n3\r\n","questionVideo":"https://www.youtube.com/embed/-XKCmbt0l-4","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"8c6022a5-8654-4226-918f-8110af738bd4","name":"Stacks For Intermediate","slug":"stacks-for-intermediate-688","type":0},{"id":"1b559022-f135-4213-9a4a-116028507474","name":"Number Of Recent Calls","slug":"number-of-recent-calls","type":1}],"next":{"id":"79910238-a3bd-44be-8754-518fb758872c","name":"Number Of Recent Calls MCQ","type":0,"slug":"number-of-recent-calls-mcq"},"prev":{"id":"d5b4ff91-fd68-4ccf-9d4f-267076ebded9","name":"Design Hit Counter Medium","type":3,"slug":"design-hit-counter-medium"}}}`

# Number Of Recent Calls

You have a RecentCounter class which counts the number of recent requests within a certain time frame. Implement the RecentCounter class: 1. RecentCounter() Initializes the counter with zero recent requests. 2. int ping(int t) Adds a new request at time t, where t represents some time in milliseconds, and returns the number of requests that has 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.

`{"id":"41837b53-12f3-4b3f-a73c-5894120d14c2","name":"Number Of Recent Calls","description":"You have a RecentCounter class which counts the number of recent requests within a certain time frame.\r\n\r\nImplement the RecentCounter class:\r\n1. RecentCounter() Initializes the counter with zero recent requests.\r\n2. int ping(int t) Adds a new request at time t, where t represents some time in milliseconds, and returns the number of requests that has 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].\r\n\r\nIt is guaranteed that every call to ping uses a strictly larger value of t than the previous call.\r\n","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1. 1 &lt;= t &lt;= 10^9\r\n2. Each test case will call ping with strictly increasing values of t.","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\nclass RecentCounter {\n public:\n // write your code here\n int ping(int t){\n return 0;\n }\n };\n\nint main(){ \n RecentCounter obj ;\n string input;\n while(getline(cin, input)){\n int data = stoi(input);\n int result = obj.ping(data);\n cout<< result<<endl;\n }\n \n return 0;\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n public static class RecentCounter {\r\n\r\n public RecentCounter() {\r\n }\r\n\r\n public int ping(int t) {\r\n return 0;\r\n }\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n RecentCounter obj = new RecentCounter();\r\n\r\n while (read.ready()) {\r\n int val = Integer.parseInt(read.readLine());\r\n int ans = obj.ping(val);\r\n System.out.println(ans);\r\n }\r\n\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"1\r\n100\r\n3001\r\n3002","sampleOutput":"1\r\n2\r\n3\r\n3\r\n","questionVideo":"https://www.youtube.com/embed/-XKCmbt0l-4","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"8c6022a5-8654-4226-918f-8110af738bd4","name":"Stacks For Intermediate","slug":"stacks-for-intermediate-688","type":0},{"id":"1b559022-f135-4213-9a4a-116028507474","name":"Number Of Recent Calls","slug":"number-of-recent-calls","type":1}],"next":{"id":"79910238-a3bd-44be-8754-518fb758872c","name":"Number Of Recent Calls MCQ","type":0,"slug":"number-of-recent-calls-mcq"},"prev":{"id":"d5b4ff91-fd68-4ccf-9d4f-267076ebded9","name":"Design Hit Counter Medium","type":3,"slug":"design-hit-counter-medium"}}}`

Editor

# Number Of Recent Calls

easy

You have a RecentCounter class which counts the number of recent requests within a certain time frame. Implement the RecentCounter class: 1. RecentCounter() Initializes the counter with zero recent requests. 2. int ping(int t) Adds a new request at time t, where t represents some time in milliseconds, and returns the number of requests that has 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.

## Constraints

1. 1 <= t <= 10^9 2. Each test case will call ping with strictly increasing values of t.

## Format

### Input

Input is managed for you

### Output

Output is managed for you

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}1 100 3001 3002```

### Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}1 2 3 3 ```

Question Video

Discussions

Show Discussion

Related Resources