PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches

Quick Overview

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.

  • easy
  • Pinterest
  • Coding & Algorithms
  • Data Scientist

Compute average unique pins per user

Company: Pinterest

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

Implement a function avg_unique_pins(user_to_pins: dict[str, list[int]]) -> float that returns the mean number of unique pin IDs per user. Treat a missing or empty list as 0 unique pins; ignore None values within lists; input may be large, so target O(total_items) time and O(U) space where U is total unique pins observed. Return a float rounded to two decimals. Example: for {"user1": [1,2,2], "user2": [1,2,3]} the result is 2.50. Include unit tests covering: empty dict (expect 0.00), users with empty lists, and users sharing overlapping pins.

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.

You are given a dictionary that maps each user ID to a list of pin IDs. Compute the average number of unique, non-None pin IDs per user. Rules: - Count unique pins separately for each user. - Duplicate pin IDs in the same user's list should only be counted once. - Ignore None values inside a user's list. - If a user's value is None or an empty list, that user contributes 0 unique pins. - If the input dictionary is empty, return 0.0. - Return the final average as a float rounded to two decimal places.

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.

Input: ({'user1': [1, 2, 2], 'user2': [1, 2, 3]},)

Expected Output: 2.5

Explanation: user1 has 2 unique pins: {1, 2}. user2 has 3 unique pins: {1, 2, 3}. Average = (2 + 3) / 2 = 2.5.

Input: ({'a': [1, None, 1, 2], 'b': [2, 2, None, 3, 3, 4], 'c': []},)

Expected Output: 1.67

Explanation: a has 2 unique valid pins: {1, 2}. b has 3: {2, 3, 4}. c has 0. Average = (2 + 3 + 0) / 3 = 1.666..., which rounds to 1.67.

Input: ({'solo': [None, 5, 5, 5]},)

Expected Output: 1.0

Explanation: The only valid unique pin is 5, so the average is 1 / 1 = 1.0.

Hints

  1. A set is useful for counting distinct pin IDs for one user while ignoring duplicates.
  2. Make sure you divide by the total number of users in the dictionary, even if some users have empty lists or only None values.
Last updated: May 12, 2026

Loading coding console...

PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Design Hierarchical Permission Checks - Pinterest (medium)
  • Implement weighted random choice - Pinterest (medium)
  • Solve five hard algorithm problems - Pinterest
  • Sample a string by real-valued scores - Pinterest (hard)
  • Find First Prefix-Matching Word - Pinterest (medium)