#C13387. Log Analysis and Summary Report

    ID: 42919 Type: Default 1000ms 256MiB

Log Analysis and Summary Report

Log Analysis and Summary Report

You are given a series of log entries from a web server. Each valid log entry is in the format timestamp request_type resource (each separated by a space). Malformed entries (i.e. those not having exactly three parts) should be ignored. Your task is to compute the following:

  1. The total number of valid log requests.
  2. A breakdown of the counts for each request type (for example: GET, POST, etc.).
  3. The most frequently accessed resource.

If there are no valid entries, output the most frequent resource as (null).

The expected time complexity is (O(n)), where (n) is the number of log entries.

inputFormat

The first line of input contains a single integer (n), the number of log entries. Each of the following (n) lines contains a log entry string with three space-separated fields: timestamp, request type, and resource accessed. Lines that do not consist of exactly three fields are considered malformed and must be ignored.

outputFormat

Output a single JSON-formatted object (as a string) with three keys:

  • total_requests: The total count of valid log entries.
  • request_type_counts: An object (dictionary) mapping each request type to its count.
  • most_frequent_resource: The resource that occurs most frequently among the valid entries, or null if there are no valid entries.
## sample
0
{"total_requests":0,"request_type_counts":{},"most_frequent_resource":null}