Normalize and Aggregate Error Logs
Problem statement
Each log is encoded as timestamp|errorCode|link|api. Normalize its link by replacing every decimal digit with #, then group logs with the same error code, API, and normalized link.
Return one row per group as errorCode|api|normalizedLink|count, sorted lexicographically by the complete first three fields.
Function
aggregateErrors(logs: String[]) → String[]Examples
Example 1
logs = ["10|E1|/users/123|GET","11|E1|/users/456|GET","12|E2|/users/123|GET"]return = ["E1|GET|/users/###|2","E2|GET|/users/###|1"]The two E1 links normalize to the same tuple.
Example 2
logs = ["1|ERR|/v2/a9|POST","2|ERR|/v20/a8|POST"]return = ["ERR|POST|/v##/a#|1","ERR|POST|/v#/a#|1"]Digit replacement preserves how many digits each link contained and the rows are sorted lexicographically.
Example 3
logs = ["1|A|/x|GET"]return = ["A|GET|/x|1"]A link without digits is unchanged.
Constraints
1 <= logs.length <= 200000.- Every log has exactly four non-empty fields separated by
|. - Fields contain printable ASCII characters other than
|; each log is at most 500 characters.