Compute average unique pins per user
Company: Pinterest
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Technical Screen
Quick Answer: This question evaluates a candidate's ability to process collections and compute aggregated metrics, including per-user deduplication of items, handling of missing/null entries, numeric averaging and rounding.
Constraints
- 0 <= number of users
- Each dictionary value is either None or a list that may contain integers and None values
- Count uniqueness per user, not across all users
- Target time complexity: O(total_items), where total_items is the total number of entries across all user lists
- Use only a temporary set per user to track uniqueness
Examples
Input: ({},)
Expected Output: 0.0
Explanation: There are no users, so the average unique pin count is 0.0.
Input: ({'u1': [], 'u2': [None, None], 'u3': None},)
Expected Output: 0.0
Explanation: Each user has 0 valid unique pins, so the average is (0 + 0 + 0) / 3 = 0.0.
Hints
- A set is useful for counting distinct pin IDs for one user while ignoring duplicates.
- Make sure you divide by the total number of users in the dictionary, even if some users have empty lists or only None values.