Problem · String
Large Responses
Learn this problemProblem statement
You are given Apache-style HTTP log records in records. Each non-empty record ends with a nonnegative integer giving the number of response bytes.
A response is large when it contains more than 5000 bytes. Return a two-element array:
- the number of large responses;
- the total bytes sent by all large responses.
The request portion may contain spaces and is enclosed in double quotes, so parse the byte count from the final whitespace-separated field.
Function
summarizeLargeResponses(records: String[]) → long[]Examples
Example 1
records = ["unicom96.unicomp.net - - [01/Jul/1995:00:00:06 -0400] \"GET /shuttle/countdown/ HTTP/1.0\" 200 3985","unicom96.unicomp.net - - [01/Jul/1995:00:00:14 -0400] \"GET /shuttle/countdown/count.gif HTTP/1.0\" 200 40310","d104.aa.net - - [01/Jul/1995:00:00:15 -0400] \"GET /shuttle/countdown/count.gif HTTP/1.0\" 200 40310"]return = [2,80620]Two records have more than 5000 bytes. Their byte counts sum to 40310 + 40310 = 80620.
Example 2
records = ["host - - [time] \"GET /a HTTP/1.0\" 200 5000","host - - [time] \"GET /b HTTP/1.0\" 200 5001"]return = [1,5001]A response of exactly 5000 bytes is not large; only the 5001-byte response qualifies.
Constraints
2 ≤ records.length ≤ 10^5- Every non-empty record ends with a valid nonnegative byte count.
- The total bytes across all large responses does not exceed
10^14.
More Postman problems
- Configuration SystemOA · Seen Sep 2020
- Minimum Swaps to Sort an ArrayOA · Seen Aug 2020
- Validate IP AddressOA · Seen Aug 2020
- Without WhitespacesOA · Seen Sep 2019
- Maximum Laptop Rating in a Price RangeOA · Seen Aug 2019
- Encode and Decode a String StreamONSITE INTERVIEW
- Group Duplicate Files by ContentONSITE INTERVIEW