← Pinterest Interview Insights

Pinterest·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Pinterest data scientist coding screen, two parts back to back. Pretty much pure Python, no SQL, which I wasn't fully expecting. The problems themselves weren't brutal but the edge cases tripped me up a bit.

Questions Asked (2)

Q1

Given a list of pin engagement records and a category lookup map, find the category with the highest average time spent among video pins only. Null time values should be excluded, ties broken alphabetically by category name. Return the category name and rounded average. Must run in O(n).

Algorithms & Data StructuresProduct Analytics & Metrics
Author's notes

The None handling was the first thing I fumbled.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the data schema and confirm that the category lookup maps each pin to a category. Then, in a single pass over the records, filter for video pins with non-null time values, accumulate sum and count per category using a hash map, and finally compute averages to find the maximum with alphabetical tie-breaking. This achieves O(n) time and O(k) space where k is the number of categories.

Pro tip: Mention that you would validate the category lookup covers all pins and handle missing categories gracefully, as data quality issues are common in production analytics. Also, emphasize that you would use a streaming approach to handle large datasets efficiently.

1. Clarify requirements and data schema

Ask about the structure of engagement records (fields like pin_id, time_spent, is_video) and the category lookup map. Confirm that 'video pins' are identified by a flag or content type, and that null time values should be skipped.

2. Design O(n) algorithm

Plan a single pass over the records: for each video pin with non-null time, look up its category and update running sum and count in a hash map. This avoids sorting or multiple passes.

3. Handle edge cases and tie-breaking

Consider cases where no video pins exist, all times are null, or multiple categories have the same average. For ties, compare category names alphabetically and choose the lexicographically smaller one.

4. Compute and return result

After processing, iterate through the hash map to compute averages, track the maximum, and apply tie-breaking. Return the category name and the average rounded to the desired precision (e.g., two decimal places).

5. Analyze complexity and test

Confirm O(n) time and O(k) space. Walk through a small example to verify correctness, including tie-breaking and null exclusion.

Key Points to Mention

  • Single-pass accumulation using a hash map to achieve O(n) time complexity.
  • Filtering criteria: only video pins and non-null time values.
  • Tie-breaking rule: alphabetical order by category name when averages are equal.
  • Rounding the average to the required precision (e.g., two decimal places).
  • Handling edge cases: empty input, no video pins, all null times, missing category mappings.
  • Space complexity O(k) where k is the number of distinct categories.

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

Q2

Given a mapping of users to lists of pin IDs they interacted with (including duplicates), compute the average number of unique pin IDs per user. Users with empty lists count as zero. Return a float rounded to 2 decimal places, targeting O(total items) time and O(number of users) extra space.

Algorithms & Data Structures
Author's notes

Simpler than part A but I overcomplicated it at first by trying to deduplicate globally instead of per user.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Iterate through each user's list of pin IDs, using a set to count unique pins per user, then accumulate the total unique counts. Finally, divide by the number of users and round to 2 decimal places. This achieves O(total items) time and O(number of users) extra space.

Pro tip: Clarify edge cases upfront: empty lists count as zero, and if there are no users, return 0.0. Also, mention that using a set per user is efficient because it avoids storing all unique pins globally, keeping space proportional to the number of users.

1. Understand the problem and constraints

Restate the problem: compute average unique pins per user, with empty lists as zero. Confirm time and space complexity goals.

2. Design the algorithm

For each user, convert their list to a set to get unique pins, then sum the sizes. Divide by total users and round to 2 decimals.

3. Handle edge cases

Consider empty input (no users) and users with empty lists. Ensure division by zero is handled.

4. Analyze complexity

Explain that iterating through all items takes O(N) time, and storing sets per user takes O(U) space, where U is number of users.

5. Implement and test

Write clean code, test with sample data including duplicates and empty lists, and verify rounding.

Key Points to Mention

  • Use a set per user to count unique pins efficiently.
  • Time complexity O(N) where N is total number of pin interactions.
  • Space complexity O(U) where U is number of users, as sets are temporary per user.
  • Handle empty lists and empty input gracefully.
  • Round the final average to 2 decimal places using appropriate rounding.
  • Consider using a running sum to avoid storing all unique counts.

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