Top Error Types in a Time Window
Problem statement
Each response row is [timestamp, errorType], where timestamp is a decimal integer string. Count errors in the half-open interval [startTime, endTime).
Return at most k rows formatted as errorType|count. Rank larger counts first and break equal-count ties by lexicographically smaller error type. If fewer than k error types occur in the interval, return all of them.
Function
topErrorTypes(responses: String[][], startTime: long, endTime: long, k: int) → String[]Examples
Example 1
responses = [["100","timeout"],["105","validation"],["108","timeout"],["110","auth"],["112","validation"],["115","timeout"]]startTime = 105endTime = 115k = 2return = ["validation|2","auth|1"]The left boundary is included and the right boundary is excluded. Validation occurs twice; auth and timeout tie once, so auth wins lexicographically.
Constraints
0 <= responses.length <= 200000.0 <= timestamp, startTime, endTime <= 10^18andstartTime < endTime.1 <= k <= 100000.- Error types are non-empty printable ASCII strings containing neither
|nor a newline.