A status page shows how many health-check pings arrived recently. Write a class PingCounter:
new PingCounter() starts with no pings.ping(t) records a ping at time t in milliseconds and returns how many pings happened in the last 3000 milliseconds, counting both ends: every ping with a time from t - 3000 to t, including this one.Each call's t is strictly larger than the previous call's.
Each example lists the calls in order, then each call's arguments. The first call creates the object with new PingCounter(…); the output lists what each call returns (null for the constructor and for methods that return nothing).
Input: ["PingCounter","ping","ping","ping","ping"] [[],[1],[100],[3001],[3002]] Output: [null,1,2,3,3]
At 3001 the range is 1 to 3001, so all three pings count. At 3002 the ping at 1 is too old.
Input: ["PingCounter","ping"] [[],[5000]] Output: [null,1]
The first ping is the only one.
1 <= t <= 10^910^4 calls.Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #258 Count Pings in the Last Three Seconds. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.