Skip to content

Commit

Permalink
Create NumberofRecentCalls.cpp
Browse files Browse the repository at this point in the history
Easy
  • Loading branch information
Rahuldandotiya committed Apr 20, 2020
1 parent e3f0748 commit 77ee265
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions NumberofRecentCalls.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class RecentCounter {
public:
queue<int> q;
RecentCounter() {

}

int ping(int t) {
if(!q.empty()){
int time=q.front();
while(!q.empty() and t-time>3000){
q.pop();
time=q.front();
}
q.push(t);
}
else q.push(t);
return q.size();
}
};

/**
* Your RecentCounter object will be instantiated and called as such:
* RecentCounter* obj = new RecentCounter();
* int param_1 = obj->ping(t);
*/

0 comments on commit 77ee265

Please sign in to comment.