#K1036. Filter and Group Logs

    ID: 23229 Type: Default 1000ms 256MiB

Filter and Group Logs

Filter and Group Logs

You are given a list of log entries. Each log entry is in the format YYYY-MM-DD:USER:ACTION.

Your task is to filter out all logs where the ACTION is UNKNOWN and then group the remaining logs by the date. For each date, record the strings in the format USER:ACTION (maintaining the order of appearance).

More formally, let \( n \) be the number of logs. For each valid log entry that does not contain the action UNKNOWN, add \( USER:ACTION \) into the list corresponding to the given date.

The output should be a JSON object (dictionary) where keys are dates and values are arrays of USER:ACTION strings.

inputFormat

The input is read from stdin and has the following format:

  • The first line contains a single integer n, representing the number of log entries.
  • The next n lines each contain a log entry in the format YYYY-MM-DD:USER:ACTION.

All input values are separated by newline characters.

outputFormat

Print a JSON object to stdout that groups the valid logs by date. The keys in the JSON object are the dates and the values are arrays of strings in the format USER:ACTION. Only logs where the ACTION is not UNKNOWN should be included. If no valid logs exist for the input, output an empty JSON object: {}.

## sample
3
2023-08-01:John:Login
2023-08-01:Jane:Logout
2023-08-02:John:Login
{"2023-08-01": ["John:Login", "Jane:Logout"], "2023-08-02": ["John:Login"]}