Katkat

Compute average unique pins per user

PinterestData Scientist · Technical Screen

Last updated

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.

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.