← Pinterest Interview Insights

Pinterest·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Pinterest data science coding screen, one question the whole time. Pretty focused on correctness plus efficiency, and they wanted unit tests at the end which I almost forgot about.

Questions Asked (1)

Q1

Write a function that takes a mapping of users to lists of pin IDs and returns the mean number of unique pin IDs per user, rounded to two decimal places. Empty or missing lists count as zero, None values inside lists should be ignored, and the solution should run in O(total items) time with O(unique pins) space.

Algorithms & Data StructuresProduct Analytics & Metrics
Author's notes

The deduplication part was fine but I initially used a global set across all users which tanked my space complexity.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify edge cases (empty mapping, None values, duplicate pins) and state assumptions. Use a set per user to deduplicate pins while ignoring None, then compute the mean of set sizes. Ensure O(total items) time by iterating each list once and O(unique pins) space by storing only unique pins per user.

Pro tip: Mention that using a set per user is optimal for deduplication, but if memory is a concern, you could process users sequentially and reuse a single set, clearing it between users—this keeps space O(max unique pins per user) rather than O(total unique pins).

1. Clarify requirements and edge cases

Ask about empty mapping, None values, duplicate pins, and whether the mean should be computed over all users or only those with pins. Confirm rounding behavior.

2. Choose data structures

Use a set per user to track unique pin IDs, ignoring None. This gives O(1) average insertion and deduplication.

3. Iterate and count

Loop through each user's list, add non-None pins to the set, then record the set size. Sum these sizes and count users.

4. Compute mean and round

Divide the total unique pins by the number of users (or return 0 if no users). Round to two decimal places using appropriate rounding (e.g., round half up).

5. Analyze complexity

Explain that time is O(total items) because each pin is processed once, and space is O(unique pins) due to the sets.

Key Points to Mention

  • Handling edge cases: empty mapping, empty lists, None values, and duplicate pins.
  • Using a set for O(1) deduplication and ignoring None values.
  • Time complexity: O(total items) because each pin is visited once.
  • Space complexity: O(unique pins) because sets store only unique non-None pins.
  • Rounding to two decimal places: use round() or format, and consider floating-point precision.
  • Product analytics context: mean unique pins per user is a key engagement metric at Pinterest.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.