Summarize the Latest Event for Each Device
Problem statement
Each device event is [eventId, deviceId, status, timestamp], where the timestamp is a nonnegative decimal integer.
Return one row [deviceId, latestStatus, latestTimestamp, eventCount] per device. Preserve the order in which device IDs first appear. A later input event wins when timestamps tie, and the input must not be mutated.
Function
summarizeByDevice(events: String[][]) → String[][]Examples
Example 1
events = [["e1","d1","online","10"],["e2","d2","offline","8"],["e3","d1","offline","14"]]return = [["d1","offline","14","2"],["d2","offline","8","1"]]Device d1 uses its later event and has two total events.
Example 2
events = [["a","x","online","5"],["b","x","offline","5"]]return = [["x","offline","5","2"]]The later input wins a timestamp tie.
Example 3
events = []return = []No events produce no summaries.
Constraints
0 <= events.length <= 100000.- Status is
onlineoroffline. - Timestamps fit in a signed 64-bit integer.