← Pinterest Interview Insights

Pinterest·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

Pinterest data scientist coding screen, one question the whole time. Pretty focused on pandas manipulation with some edge case gotchas baked in. Left feeling okay about it but not confident.

Questions Asked (1)

Q1

Given a pandas DataFrame with pin engagement data and a dict mapping category IDs to names, write Python to find the category with the highest average time spent among video pins only. Filter out null category IDs and non-positive time values, break ties by lexicographic order on category name, and return a tuple of (category_name, avg_time) rounded to two decimals. Solution should run in O(n) time with O(k) extra space for k distinct categories.

Algorithms & Data StructuresProduct Analytics & Metrics
Author's notes

I started grouping by category_id right away and almost forgot to filter the nulls before the join with the category_map dict.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clearly restating the problem and clarifying assumptions (e.g., what defines a video pin, how to handle ties). Then outline an O(n) single-pass solution using a dictionary to accumulate sum and count per category, followed by a scan to compute averages and select the best. Finally, write clean Python code with vectorized pandas operations or a manual loop, and test edge cases.

Pro tip: Mention that you would verify the data types and handle missing values before aggregation, and that you'd use a single pass to compute sums and counts to achieve O(n) time. Also, note that tie-breaking by lexicographic order can be done by comparing category names only when averages are equal.

1. Clarify requirements and edge cases

Confirm the definition of 'video pins', how to treat null category IDs, non-positive time values, and ties. Ask about data size and expected output format.

2. Design an O(n) algorithm

Use a dictionary to accumulate sum of time and count per category in one pass over the DataFrame, filtering out invalid rows. Then compute averages and find the max with tie-breaking.

3. Implement in Python/pandas

Write code that filters the DataFrame, groups by category, computes mean, and selects the top category. Alternatively, use a manual loop for explicit O(n) control.

4. Handle tie-breaking and rounding

When multiple categories have the same average, choose the one with lexicographically smallest name. Round the final average to two decimals.

5. Test and validate

Test with edge cases: no valid rows, all same averages, null categories, zero/negative times. Verify time and space complexity.

Key Points to Mention

  • Filtering conditions: video pins only, non-null category IDs, time > 0
  • Single-pass aggregation using a dictionary to track sum and count per category
  • Time complexity O(n) and space complexity O(k) where k is number of distinct categories
  • Tie-breaking logic: compare category names lexicographically when averages are equal
  • Rounding the final average to two decimal places
  • Using pandas groupby with mean and idxmax, or manual loop for explicit control

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