FastPrepTop Error Types in a Time Window

Top Error Types in a Time Window

Notion logoNotion● MediumFULLTIMEONSITE INTERVIEW
Learn

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^18 and startTime < endTime.
  • 1 <= k <= 100000.
  • Error types are non-empty printable ASCII strings containing neither | nor a newline.

More Notion problems

See Notion hiring insights
public String[] topErrorTypes(String[][] responses, long startTime, long endTime, int k) {
    // Write your code here.
}
responses[["100","timeout"],["105","validation"],["108","timeout"],["110","auth"],["112","validation"],["115","timeout"]]
startTime105
endTime115
k2
expected["validation|2", "auth|1"]
Checking account…