Problem · String

Large Responses

Learn this problem
EasyPostman logoPostmanFULLTIMEOA

Problem 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:

  1. the number of large responses;
  2. 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

drafts saved locally
public long[] summarizeLargeResponses(String[] records) {
    // write your code here
}
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"]
expected[2,80620]
checking account