← Pinterest Interview Insights

Pinterest·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Pinterest DS interview with four back-to-back technical problems, two SQL and two Python/pandas. The questions were all grounded in Pinterest's actual product data model which was a nice touch, but the definitions were dense and easy to misread under pressure.

Questions Asked (4)

Q1

Write a SQL query that computes click-through rate broken down by pin format and event date, but only for users who are considered 'new' at the time of the event and are located in the US.

Product Analytics & MetricsData Modeling
Author's notes

The 'new user' definition is what gets you.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the definitions of 'new user', 'click-through rate', and 'pin format', then outline the necessary tables and joins. Write the query in steps: first identify new US users at event time, then aggregate impressions and clicks by pin format and event date, and finally compute CTR as clicks divided by impressions.

Pro tip: Mention that you would validate the query by checking edge cases, such as users with no impressions or clicks, and ensure that the date filtering for 'new' users is correctly applied relative to the event date. Also, consider performance implications and suggest indexing or partitioning strategies.

1. Clarify definitions and assumptions

Define what 'new user' means (e.g., first event within 7 days), what constitutes a click and an impression, and how pin formats are categorized. Confirm the time frame for 'new' status and the event date granularity.

2. Identify relevant tables and joins

Determine which tables contain user events (impressions, clicks), user attributes (location, signup date), and pin metadata (format). Plan joins on user_id and pin_id, ensuring proper filtering for US users and new users at event time.

3. Filter for new US users at event time

Use a subquery or join to select users who were new when the event occurred (e.g., event_date between signup_date and signup_date + 7 days) and whose location is US. Apply this filter before aggregation to avoid unnecessary computation.

4. Aggregate clicks and impressions by pin format and event date

Group by pin format and event date, counting clicks and impressions separately. Ensure that clicks are only counted for events that are clicks, and impressions for all relevant events.

5. Compute CTR and handle edge cases

Calculate CTR as clicks divided by impressions, using NULLIF to avoid division by zero. Consider rounding or formatting the result. Optionally, include a check for statistical significance or minimum volume.

Key Points to Mention

  • Definition of 'new user' and how to determine it at event time (e.g., using signup date and event date).
  • Importance of filtering for US location and ensuring the filter is applied correctly.
  • Handling of impressions and clicks: ensuring clicks are a subset of impressions and avoiding double-counting.
  • Use of appropriate date functions and time zone considerations.
  • Performance optimization: filtering early, using indexes, and avoiding unnecessary joins.
  • Validation: checking for NULLs, zero impressions, and ensuring the query returns expected results.

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

Q2

Write a SQL query to find what percentage of users saw at least one 'fresh' pin during a reporting window, where a fresh pin is defined as one that received at least 2 total impressions within 7 days of its creation.

Product Analytics & MetricsData Modeling
Author's notes

Two-stage logic and I fumbled the first stage a bit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Break the problem into two parts: first identify 'fresh' pins by checking if they received at least 2 impressions within 7 days of creation, then find users who saw at least one such pin during the reporting window. Finally, compute the percentage by dividing the count of distinct users who saw a fresh pin by the total distinct users active in the window, multiplying by 100.

Pro tip: Clarify the definition of 'saw'—it could mean impression or engagement—and confirm the reporting window boundaries. Also, consider whether to include users with zero impressions in the denominator; typically, the denominator is all users active in the window, not just those who saw any pin.

1. Clarify definitions and assumptions

Confirm what 'saw' means (e.g., impression event), the exact reporting window, and whether 'fresh' pins are determined globally or per user. State assumptions clearly.

2. Identify fresh pins

Write a subquery to find pins that received at least 2 impressions within 7 days of their creation timestamp. This may involve joining pin creation data with impression events and filtering by time difference.

3. Find users who saw fresh pins

Join the fresh pins list with impression events during the reporting window to get distinct users who saw at least one fresh pin.

4. Compute total active users

Determine the total number of distinct users who were active (e.g., had any impression) during the reporting window.

5. Calculate percentage

Divide the count of users who saw a fresh pin by the total active users, multiply by 100, and round as needed.

Key Points to Mention

  • Definition of 'fresh' pin: at least 2 impressions within 7 days of creation, which requires a self-join or window function on impressions.
  • Definition of 'saw': typically an impression event, but could be a click or engagement; clarify with interviewer.
  • Reporting window: specify start and end dates; ensure impressions for fresh pin determination may occur outside the window.
  • Handling of users with no impressions: decide whether they count in the denominator; usually only active users are considered.
  • Use of DISTINCT counts to avoid double-counting users who saw multiple fresh pins.
  • Performance considerations: indexing on user_id, pin_id, and timestamps; possibly use CTEs for readability.

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

Q3

Given a dictionary mapping board IDs to lists of pins, write a Python function that takes a target pin and returns all other pins ranked by how many boards they share with that pin. Support an optional parameter to limit results to the top N.

Algorithms & Data Structures
Author's notes

Pretty clean problem once you see it as a co-occurrence count.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem: the input is a dictionary mapping board IDs to lists of pins, and we need to rank other pins by the number of boards they share with the target pin. Then, design an efficient algorithm using an inverted index from pin to boards, compute intersections, and sort by shared board count, with an optional top-N parameter.

Pro tip: Mention that in a real Pinterest-scale system, you'd precompute pin co-occurrence or use approximate methods like MinHash/LSH, but for this problem, an exact solution with an inverted index is expected. Also, discuss handling ties and the time/space trade-offs.

1. Clarify requirements and edge cases

Ask about input size, whether boards can have duplicate pins, and if the target pin is guaranteed to exist. Clarify that 'other pins' excludes the target pin itself and that ranking is by descending shared board count.

2. Build an inverted index

Create a mapping from each pin to the set of boards it appears on. This allows O(1) lookup of boards for any pin and efficient intersection.

3. Compute shared board counts

For the target pin, get its board set. For each other pin, compute the size of the intersection between its board set and the target's board set. Use a dictionary to accumulate counts.

4. Sort and limit results

Sort the pins by shared board count in descending order. If the optional top-N parameter is provided, return only the first N results; otherwise, return all.

5. Analyze complexity and optimize

Discuss time complexity: O(P * B) where P is number of pins and B is average boards per pin, but can be optimized by iterating over boards of the target pin and incrementing counts for other pins on those boards. Space complexity O(P + B).

Key Points to Mention

  • Use of an inverted index (pin to boards) for efficient lookups
  • Set intersection to compute shared boards, leveraging Python's set operations
  • Time and space complexity analysis, including optimizations like iterating over boards of the target pin
  • Handling of ties in ranking (e.g., stable sort or arbitrary order)
  • Optional top-N parameter implementation using heapq.nlargest or sorting and slicing
  • Edge cases: target pin not present, empty boards, duplicate pins in a board

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

Q4

Using a pandas DataFrame of user engagement data, find the category with the highest average time spent among video pins only. The category name comes from an external mapping dict, and missing or null category IDs should be labeled 'unknown'. Also explain how you'd handle ties.

Product Analytics & MetricsAlgorithms & Data Structures
Author's notes

Mostly a pandas groupby question but the null handling is where people slip.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, filter the DataFrame to include only video pins, then map category IDs to names using the external dictionary, filling missing or null IDs with 'unknown'. Group by category name, compute the average time spent, and identify the category with the highest average. For ties, return all tied categories or specify a tie-breaking rule such as alphabetical order.

Pro tip: Mention that you would validate the mapping dictionary for missing keys and consider using vectorized operations for efficiency, especially with large datasets. Also, discuss how you would handle ties in a way that aligns with business needs, such as reporting all ties or selecting the one with the most data points.

1. Filter video pins

Subset the DataFrame to include only rows where the pin type is 'video' to focus the analysis on video pins.

2. Map category IDs to names

Use the external mapping dictionary to convert category IDs to category names, and replace missing or null IDs with 'unknown'.

3. Compute average time spent per category

Group the filtered DataFrame by category name and calculate the mean of the time spent column for each category.

4. Identify the top category

Find the category with the highest average time spent. If there are ties, decide whether to return all tied categories or apply a tie-breaking rule.

5. Explain tie handling

Articulate how you would handle ties, such as returning all tied categories, selecting the one with the most observations, or using alphabetical order, and justify your choice.

Key Points to Mention

  • Filtering the DataFrame for video pins only.
  • Handling missing or null category IDs by mapping them to 'unknown'.
  • Using groupby and mean aggregation to compute average time spent per category.
  • Identifying the maximum average and extracting the corresponding category.
  • Strategies for tie-breaking: return all ties, choose by count, or alphabetical order.
  • Ensuring efficient and readable code, possibly using vectorized operations.

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