問題文
function solution(events, threshold, cooldownMs)を書いてください。入出力はJSON値です。入力配列やオブジェクトを変更しないでください。外部ライブラリ・ネットワーク・非同期関数は使えません。 events:{timestamp:nonnegative integer,ok:boolean}[] in nondecreasing time; threshold:positive integer; cooldownMs:nonnegative integer. Initially closed with zero failures. Reject while timestamp<openUntil without changing state. At/after expiry reset to closed and zero failures before accepting. Accepted success resets failures; failure increments them and reaching threshold opens until timestamp+cooldownMs. Return {accepted,state:'open'|'closed'} after each event. Zero cooldown is valid. 入力範囲:各入力配列は最大50,000項目、文字列は最大1,000文字です。数値は有限値で、整数と整数の合算結果はJavaScriptの安全な整数範囲内です。その他の型と有効性は上記の規則に従います。
入出力例
例 1
関数の引数
[
[
{
"timestamp": 0,
"ok": false
},
{
"timestamp": 1,
"ok": false
},
{
"timestamp": 2,
"ok": true
},
{
"timestamp": 11,
"ok": true
}
],
2,
10
]戻り値
[
{
"accepted": true,
"state": "closed"
},
{
"accepted": true,
"state": "open"
},
{
"accepted": false,
"state": "open"
},
{
"accepted": true,
"state": "closed"
}
]例 2
関数の引数
[
[
{
"timestamp": 0,
"ok": false
},
{
"timestamp": 10,
"ok": false
},
{
"timestamp": 20,
"ok": true
}
],
1,
10
]戻り値
[
{
"accepted": true,
"state": "open"
},
{
"accepted": true,
"state": "open"
},
{
"accepted": true,
"state": "closed"
}
]例 3
関数の引数
[
[
{
"timestamp": 0,
"ok": false
},
{
"timestamp": 10,
"ok": false
},
{
"timestamp": 10,
"ok": true
}
],
1,
10
]戻り値
[
{
"accepted": true,
"state": "open"
},
{
"accepted": true,
"state": "open"
},
{
"accepted": false,
"state": "open"
}
]