Website Activity Analytics

Asked at GooglePhone screen

Reported by the problem's creator, not verified

A website keeps a log of what its users do. You are given the list of records records, where each record is a dictionary with the keys user_id (a string), timestamp (a string in the form YYYY-MM-DD HH:MM:SS) and activity (a string). The records can be in any order.

Implement the class ActivityAnalytics that is built from records.

Examples

  1. Example 1

    Input: init = [[{"user_id":"u1","activity":"view","timestamp":"2024-05-01 09:00:00"},{"user_id":"u2","activity":"view","timestamp":"2024-05-01 09:01:00"},{"user_id":"u1","activity":"view","timestamp":"2024-05-01 09:02:00"},{"user_id":"u1","activity":"search","timestamp":"2024-05-01 09:03:00"},{"user_id":"u3","activity":"buy","timestamp":"2024-05-01 09:04:00"},{"user_id":"u2","activity":"search","timestamp":"2024-05-01 09:05:00"},{"user_id":"u3","activity":"view","timestamp":"2024-05-01 09:06:00"},{"user_id":"u3","activity":"view","timestamp":"2024-05-01 09:07:00"}]], operations = [["unique_users",[]]]

    Output: [{"buy":1,"view":3,"search":2}]

    Explanation: view was done by u1, u2 and u3 (u1 and u3 more than once, but each counts once), search by u1 and u2, and buy by u3 only.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.