Number of Recent Calls

Given strictly increasing call timestamps in milliseconds, return one count per call, in the same order. At time t, count received timestamps in the closed…

Given strictly increasing call timestamps in milliseconds, return one count per call, in the same order. At time t, count received timestamps in the closed interval [t-3000,t], including the current call and equality at the lower endpoint. Implement count_recent_calls in Python or countRecentCalls in other languages; this is a deterministic batch function, not a class or clock API.

- 1 <= timestamps.length <= 2000. - 1 <= timestamps[i] <= 2147483647; all values are strict integers and strictly increasing. - No duplicates, decreasing timestamps, Booleans or fractional values. - Return an ordered count array of the same length; every count is between 1 and n. - Teaching traces use at most 12 timestamps within the ARRAY transport; coding retains full length/int32 bounds.

Example 1: input timestamps = [1,3001]; output [1,2]. At time 3001, time 1 is exactly 3000 milliseconds old and still counts.

Example 2: input timestamps = [1,2,3,3003]; output [1,2,3,2]. At 3003, times 1 and 2 expire, but equal endpoint 3 remains.

Example 3: input timestamps = [1,3002]; output [1,1]. Time 1 is older than the inclusive cutoff 2.

Category: Queues. Topic: queue. Difficulty: Easy. Patterns: linear-scan.