Problem statement
Write function solution(events). Inputs and outputs are JSON values. Do not modify input arrays or objects. External libraries, network access, and asynchronous functions are not supported. 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. 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
[
[
{
"id": "x",
"account": "a",
"delta": 10
},
{
"id": "x",
"account": "a",
"delta": 99
}
]
]Return value
{
"accepted": [
true,
false
],
"balances": [
{
"account": "a",
"balance": 10
}
]
}Example 2
Function arguments
[
[
{
"id": "x",
"account": "b",
"delta": 2
},
{
"id": "y",
"account": "a",
"delta": -3
}
]
]Return value
{
"accepted": [
true,
true
],
"balances": [
{
"account": "a",
"balance": -3
},
{
"account": "b",
"balance": 2
}
]
}Example 3
Function arguments
[
[
{
"id": "a",
"account": "A",
"delta": 1
},
{
"id": "b",
"account": "a",
"delta": 1
}
]
]Return value
{
"accepted": [
true,
true
],
"balances": [
{
"account": "A",
"balance": 1
},
{
"account": "a",
"balance": 1
}
]
}