Summarize the Latest Event for Each Device
Updated
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.
More OneTrust interview questions
Similar questions at other companies
- Count Distinct Underwriting PII ValuesAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
- Bounded IPv4 FilterAmazon · PHONE SCREEN
- SimpleRDD Multiset IntersectionDatologyAI · PHONE SCREEN
- Vehicle Maintenance Event ReadinessWaymo · PHONE SCREENWaymo interview questions
- Project JSON Fields into a Target FormatBooking.com · PHONE SCREEN
- Employee Training StatusVanta · PHONE SCREEN
- Select Object by Key ExtremeBridge · PHONE SCREENBridge interview questions
- Group Names by DepartmentMastercard · PHONE SCREENMastercard interview questions
- Badge Records Without a MatchWhatNot · PHONE SCREENWhatNot interview questions
- AI Role: Collection with Add and Remove OperationsApple · PHONE SCREENApple interview questions