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 is an array of {id:string,timestamp:integer,value:integer}. Keep the event with the largest timestamp for each ID. For equal timestamps keep the later occurrence in the input. Return an array ordered by the first appearance of each ID. IDs are case-sensitive. Negative timestamps are valid. 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": "a",
"timestamp": 1,
"value": 0
},
{
"id": "a",
"timestamp": 2,
"value": 5
}
]
]Return value
[
{
"id": "a",
"timestamp": 2,
"value": 5
}
]Example 2
Function arguments
[
[
{
"id": "b",
"timestamp": 1,
"value": 0
},
{
"id": "a",
"timestamp": 4,
"value": 0
},
{
"id": "b",
"timestamp": 7,
"value": 0
}
]
]Return value
[
{
"id": "b",
"timestamp": 7,
"value": 0
},
{
"id": "a",
"timestamp": 4,
"value": 0
}
]Example 3
Function arguments
[
[
{
"id": "x",
"timestamp": 1,
"value": 0
},
{
"id": "y",
"timestamp": 2,
"value": 0
},
{
"id": "z",
"timestamp": 3,
"value": 0
},
{
"id": "y",
"timestamp": 0,
"value": 0
},
{
"id": "x",
"timestamp": 4,
"value": 0
}
]
]Return value
[
{
"id": "x",
"timestamp": 4,
"value": 0
},
{
"id": "y",
"timestamp": 2,
"value": 0
},
{
"id": "z",
"timestamp": 3,
"value": 0
}
]