FastPrepAverage Process Time from CSV

Average Process Time from CSV

Abnormal Security logoAbnormal Security● EasyFULLTIMEPHONE SCREEN
Learn

Problem statement

Each CSV row has the form id,start,end, where start and end are integer timestamps and end >= start. Group rows by id and return each ID's average process duration end - start.

Return rows [id, average] sorted lexicographically by ID. The input guarantees every average is an integer.

Function

averageProcessTimes(rows: String[]) → String[][]

Examples

Example 1

rows = ["a,10,20","b,0,4","a,30,50"]return = [["a","15"],["b","4"]]

ID a has durations 10 and 20, whose average is 15.

Constraints

  • 1 <= rows.length <= 100000.
  • IDs are nonempty ASCII strings without commas.
  • 0 <= start <= end <= 10^9.
  • Each per-ID duration sum is divisible by its row count.

More Abnormal Security problems

See Abnormal Security hiring insights
public String[][] averageProcessTimes(String[] rows) {
    // Parse id,start,end rows and return sorted id,average pairs.
}
rows["a,10,20","b,0,4","a,30,50"]
expected[["a", "15"], ["b", "4"]]
Checking account…