Problem statement
Write function solution(events, limit, windowMs). Inputs and outputs are JSON values. Do not modify input arrays or objects. External libraries, network access, and asynchronous functions are not supported. events is an array of {user:string,timestamp:nonnegative integer} in globally nondecreasing timestamp order. limit and windowMs are positive integers. At time t, accept a request if that user has fewer than limit previously accepted requests in (t-windowMs,t]. Same-timestamp requests count separately. Rejected requests are not recorded. Return acceptance booleans in input order. Users are case-sensitive. timestamp and windowMs are measured in milliseconds. Input limits: at most 50,000 items per input array and 1,000 characters per string. Numbers are finite; integers and accumulated integer results stay in the JavaScript safe-integer range. Other types and validity rules follow the statement above.
Example input and output
Example 1
Function arguments
[
[
{
"user": "a",
"timestamp": 0
},
{
"user": "a",
"timestamp": 1
},
{
"user": "a",
"timestamp": 2
}
],
2,
10
]Return value
[ true, true, false ]
Example 2
Function arguments
[
[
{
"user": "a",
"timestamp": 0
},
{
"user": "a",
"timestamp": 10
}
],
1,
10
]Return value
[ true, true ]
Example 3
Function arguments
[
[
{
"user": "a",
"timestamp": 100
},
{
"user": "a",
"timestamp": 1000
},
{
"user": "a",
"timestamp": 1001
}
],
1,
10
]Return value
[ true, true, false ]