HTTP Status Log Summary
Updated
Problem statement
You are given records, a list of log lines. A valid record has exactly four fields separated by whitespace, in this order: an IPv4 address, a non-negative decimal timestamp, an API path, and an HTTP status code.
A record is valid only when all of these hold:
- The IPv4 address has four decimal octets, each from
0through255. - The timestamp is not negative and fits in a signed 64-bit integer.
- The API path starts with
/. - The status is an integer from
100through599.
Among the valid records, count the client errors, which have a status in the 400 range. Also count the server errors, which have a status in the 500 range.
The failure percentage is 100 * (client errors + server errors) / valid records. Round it to exactly two decimal places, with halves rounded up. If 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. Each N is a count, and P is the failure percentage.
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"]In the first record, the first octet of the IP address is out of range. In the second record, the timestamp is negative. Both records are invalid, so there are no valid records, no client or server errors, and the failure percentage is zero.
Constraints
1 <= records.length <= 2 * 10^5.1 <= records[i].length <= 500.- Records contain printable ASCII characters and whitespace.
More Apple Phone Screen questions
- Subarray Product Less Than KPHONE SCREEN · Seen Nov 2026
- Evaluate DivisionPHONE SCREEN · Seen Nov 2026
- Reverse a Linked ListPHONE SCREEN · Seen Nov 2026
- Validate a BST with a Custom ComparisonPHONE SCREEN · Seen Nov 2026
- Design a Food Rating SystemPHONE SCREEN · Seen Oct 2026
- Days Until Poisoned Plants StabilizePHONE SCREEN · Seen Oct 2026
- Capture Surrounded Regions with Union-FindPHONE SCREEN · Seen Oct 2026
- Maintain a Consistent-Hashing RingPHONE SCREEN · Seen Oct 2026
- Count Nodes in a ChainPHONE SCREEN · Seen Oct 2026
- Run-Length DecodingPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Business Account KYC Verification — Parts 1–5Stripe · PHONE SCREENStripe interview questions
- CSV Row SerializerMercor · PHONE SCREENMercor interview questions
- Host Log ParserVerkada · PHONE SCREENVerkada interview questions
- Length-Prefixed String CodecSnowflake · PHONE SCREENSnowflake interview questions
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Machine Message RouterOpenAI · PHONE SCREENOpenAI interview questions
- JSON Identity VerificationKikoff · PHONE SCREENKikoff interview questions
- Alert After Repeated Column Threshold BreachesMeta · PHONE SCREENMeta interview questions
- Serialize a Nested Dictionary as JSONGoogle · PHONE SCREENGoogle interview questions
- Render a Source-Backed Markdown SubsetSamsara · PHONE SCREENSamsara interview questions
Apple interview experiences
- Apple SWE Phone Screen: Subarray Products: 1 Experience
- Apple New Grad SWE Java, Coding and Manager Rounds: 1 Experience
- Apple AI Coding and Related Interviews: 17 Experiences
- Apple India SWE New Grad Interviews: 5 Experiences
- Apple New Grad SWE Phone Screens: 12 Experiences (Part 3 of 3)
- Apple New Grad SWE and Embedded: 16 Experiences (Part 2 of 3)