Given a collection of records capturing activities, return a mapping where keys are activity types and values are the counts of unique users, and calculate the average time spent on the website per user in seconds.
Asked in the Technical Phone Screen stage. Python coding question on Google Doc with edge cases to discuss.
Implement a function that takes a list of records and returns a tuple: (activity_counts, average_time_per_user).
Each record is a dictionary with keys: user_id (hashable), activity_type (string), and time_spent (non-negative integer seconds).
activity_counts: a dictionary mapping each activity_type to the number of distinct user_id values seen for that activityaverage_time_per_user: the total time_spent across all records divided by the number of distinct usersIf there are no records, return an empty mapping and 0.0.
def summarize_activity(records):