คำอธิบายโจทย์
เขียน 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"
}
]