588. Number of Recent Calls

EasyStackQueueSliding Window

You receive a series of request timestamps in increasing order. After each request at time t, return the number of requests that occurred in the inclusive window [t-3000, t]. Return the answers as an array. The input is JSON {requests}.

Input: JSON {requests}.

Output: Array — the recent-call count after each request.

Examples

Example 1
Input: {"requests":[1,100,3001,3002]}
Output: [1,2,3,3]
Explanation: The window holds the last 3000 ms.
Example 2
Input: {"requests":[1]}
Output: [1]
Explanation: A single request.
Example 3
Input: {"requests":[1,2,3,4,5]}
Output: [1,2,3,4,5]
Explanation: All within the window.

Constraints

Asked by

BloombergMetaGoogleAmazonAppleMicrosoft
Solve this problem in the editor →