Normalize and Aggregate Error Logs
Updated
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.
More Temporal interview questions
Similar questions at other companies
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- Group AnagramsWorkday · PHONE SCREEN
- Bank Account Balances (Part 2): Monthly ReconciliationStripe · PHONE SCREENStripe interview questions
- Time-Aware Search AutocompleteRoblox · PHONE SCREENRoblox interview questions
- Top Ten Most Frequent Words in a BookRobinhood · PHONE SCREENRobinhood interview questions
- Group AnagramsEPAM · PHONE SCREENEPAM interview questions
- Aggregate Matching IPv4 Addresses Across ResponsesPinterest · PHONE SCREENPinterest interview questions
- Diff Two Filesystem Hash TreesCursor · PHONE SCREENCursor interview questions
- Find Duplicate File GroupsAnthropic · PHONE SCREENAnthropic interview questions
- Group AnagramsJFrog · PHONE SCREEN