All problems

Number of Recent Calls

Easy · queue

A help line logs the moment each phone call arrives, in milliseconds since it opened. The list times holds these moments in the order the calls came in, and every call arrives strictly later than the one before it.

After each call arrives, the operator wants to know how busy the line has been lately: how many calls, including the one that just arrived, came in during the last 3000 milliseconds. For a call that arrives at time t, that means every call whose time is in the range from t - 3000 to t, with both ends included.

Return a list with one number for each call, in the same order as times.

Examples

Example 1

Input: times = [1, 100, 3001, 3002]

Output: [1, 2, 3, 3]

At 3001 the calls at 1, 100 and 3001 all fall in [1, 3001]. At 3002 the range is [2, 3002], so the call at 1 no longer counts.

Example 2

Input: times = [10, 5000, 5001]

Output: [1, 1, 2]

The call at 10 is far outside the range [2000, 5000] of the second call, so each of the first two calls sees only itself.

Constraints