คำอธิบายโจทย์
เขียน function solution(events) ข้อมูลเข้าและผลลัพธ์เป็นค่า JSON ห้ามแก้ไขอาร์เรย์หรือออบเจ็กต์ข้อมูลเข้า ไม่รองรับไลบรารีภายนอก เครือข่าย หรือฟังก์ชันแบบอะซิงโครนัส events:{id:string,account:string,delta:integer}[]. Accept only the first occurrence of each case-sensitive event ID, even if later account/delta differs. Return {accepted:boolean[],balances:[{account,balance}]}. Aggregate accepted deltas per account, include zero balances, and sort accounts using JavaScript string comparisons. All sums are safe integers. ขอบเขตข้อมูล: อาร์เรย์อินพุตแต่ละชุดมีไม่เกิน 50,000 รายการ สตริงไม่เกิน 1,000 ตัวอักษร ตัวเลขต้องเป็นค่าจำกัด จำนวนเต็มและผลรวมจำนวนเต็มอยู่ในช่วงจำนวนเต็มที่ปลอดภัยของ JavaScript ชนิดและความถูกต้องอื่นเป็นไปตามกฎด้านบน
ตัวอย่างข้อมูลเข้าและผลลัพธ์
ตัวอย่าง 1
อาร์กิวเมนต์ของฟังก์ชัน
[
[
{
"id": "x",
"account": "a",
"delta": 10
},
{
"id": "x",
"account": "a",
"delta": 99
}
]
]ค่าที่ส่งคืน
{
"accepted": [
true,
false
],
"balances": [
{
"account": "a",
"balance": 10
}
]
}ตัวอย่าง 2
อาร์กิวเมนต์ของฟังก์ชัน
[
[
{
"id": "x",
"account": "b",
"delta": 2
},
{
"id": "y",
"account": "a",
"delta": -3
}
]
]ค่าที่ส่งคืน
{
"accepted": [
true,
true
],
"balances": [
{
"account": "a",
"balance": -3
},
{
"account": "b",
"balance": 2
}
]
}ตัวอย่าง 3
อาร์กิวเมนต์ของฟังก์ชัน
[
[
{
"id": "a",
"account": "A",
"delta": 1
},
{
"id": "b",
"account": "a",
"delta": 1
}
]
]ค่าที่ส่งคืน
{
"accepted": [
true,
true
],
"balances": [
{
"account": "A",
"balance": 1
},
{
"account": "a",
"balance": 1
}
]
}