HTTP Status Log Summary
Learn this problemProblem statement
Analyze the strings in records. A valid record has exactly four whitespace-separated fields in this order: IPv4 address, non-negative decimal timestamp, API path, and HTTP status code.
A record is valid only when:
- the IPv4 address has four decimal octets from
0through255; - the timestamp fits in a signed 64-bit integer and is non-negative;
- the API path begins with
/; and - the status is an integer from
100through599.
Among valid records, count client errors in the 400 range and server errors in the 500 range. The failure percentage is 100 * (client errors + server errors) / valid records, rounded to exactly two decimal places using ordinary half-up rounding. When there are no valid records, it is 0.00.
Return exactly five strings: valid=N, invalid=N, client_errors=N, server_errors=N, and failure_percentage=P.
Function
summarizeStatusLogs(records: String[]) → String[]Examples
Example 1
records = ["10.0.0.1 100 /vote 200","10.0.0.2 101 /vote 404","bad 102 /vote 503","10.0.0.3 103 /vote 503"]return = ["valid=3","invalid=1","client_errors=1","server_errors=1","failure_percentage=66.67"]Three records are valid. Two of those three have a 4xx or 5xx status, so the failure percentage is 66.67.
Example 2
records = ["256.1.1.1 1 /x 200","1.1.1.1 -1 /x 500"]return = ["valid=0","invalid=2","client_errors=0","server_errors=0","failure_percentage=0.00"]The first IP octet is out of range and the second timestamp is negative, so neither record contributes to status metrics.
Constraints
1 <= records.length <= 2 * 10^5.1 <= records[i].length <= 500.- Records contain printable ASCII characters and whitespace.
More Apple problems
- Insert IntervalPHONE SCREEN · Seen Jul 2026
- Group Transitive String AliasesPHONE SCREEN · Seen Jul 2026
- Design Task ManagerPHONE SCREEN · Seen Jul 2026
- Unit Conversion IIPHONE SCREEN · Seen Jul 2026
- Two-Color an Undirected GraphPHONE SCREEN · Seen Jul 2026
- Word Search IIPHONE SCREEN · Seen Jul 2026
- Phone DirectoryPHONE SCREEN · Seen Jul 2026
- Product Except Self With ZerosONSITE INTERVIEW · Seen Jul 2026