← Pinterest Interview Insights

Pinterest·Data Scientist·Technical Phone Screen·Senior

SeniorPrefer not to say
Jul 2026Remote

Summary

Pinterest DS interview that was basically a gauntlet of SQL and pandas tasks built around a shopping engagement schema. No behavioral stuff, just pure technical work. The questions were detailed enough that I kept second-guessing whether I was overcomplicating things.

Questions Asked (4)

Q1

Write a single SQL query returning daily shopping engagement metrics for each date in a 7-day window, including DAU, click counts, average positive stay time, and a rolling 7-day unique user count. Deduplicate clicks within 5 minutes per user-pin pair using window functions, and use a generated dates CTE to fill in days with zero activity.

Product Analytics & MetricsData Modeling
Author's notes

This one took me a while to structure.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the schema and definitions (e.g., what constitutes a click, positive stay time, and how to handle deduplication). Then outline a multi-CTE query: generate a date spine, deduplicate clicks using window functions, aggregate daily metrics, and compute the rolling 7-day unique users. Finally, join the date spine with aggregated metrics to fill zero-activity days.

Pro tip: Mention that you would validate the deduplication logic by checking edge cases like clicks exactly 5 minutes apart, and consider using a self-join or window function with a range frame for the rolling unique count to avoid performance pitfalls.

1. Clarify requirements and schema

Ask about table structures, definitions of DAU, click, positive stay time, and the 7-day window. Confirm whether the rolling unique count is per day or over the entire window.

2. Generate date spine

Use a recursive CTE or a dates table to create a series of 7 consecutive dates covering the analysis window.

3. Deduplicate clicks

Use window functions (e.g., LAG or ROW_NUMBER with a 5-minute threshold) to flag and remove duplicate clicks for the same user-pin pair within 5 minutes.

4. Aggregate daily metrics

Compute DAU (distinct users), click counts, and average positive stay time per day from the deduplicated data.

5. Compute rolling 7-day unique users and join with date spine

Calculate the rolling 7-day unique user count using a window function with a RANGE frame, then left join the date spine with the aggregated metrics to fill zero-activity days.

Key Points to Mention

  • Use of window functions for deduplication (e.g., LAG to compare timestamps).
  • Importance of a date spine (generated dates CTE) to ensure all days are represented.
  • Definition of DAU as distinct users who performed any activity (e.g., clicks) on a given day.
  • Handling of positive stay time: only include positive values and compute average per day.
  • Rolling 7-day unique user count: use COUNT(DISTINCT user_id) over a window of 7 days, considering performance implications.
  • Edge cases: clicks exactly at 5-minute boundary, users with no activity, and ensuring zero-fill for missing days.

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

Q2

Compute next-day retention: among users who had at least one shopping click on 2025-08-31, what percentage also had a shopping click on 2025-09-01?

Product Analytics & MetricsA/B Testing & Experimentation
Author's notes

Straightforward retention query.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the metric definition and edge cases, then outline the SQL logic using a self-join or conditional aggregation on user-level daily activity. Finally, discuss how to interpret the result and potential pitfalls like time zones or bot traffic.

Pro tip: Always confirm whether the metric should be computed at the user level (unique users) or session level, and whether the denominator includes only users with clicks on the first day or all users active that day. This shows attention to detail and avoids misinterpretation.

1. Clarify the metric and assumptions

Define 'shopping click' (e.g., any click on a shopping pin or product) and confirm the date range and time zone. Ask if the denominator is users with at least one shopping click on 2025-08-31 and numerator is those who also had at least one on 2025-09-01.

2. Identify the data sources and tables

Determine which tables contain user click events (e.g., event logs, clicks table) and how to filter for shopping clicks. Ensure you have user IDs and event timestamps.

3. Write the SQL query

Use a self-join or conditional aggregation: select distinct users with shopping clicks on day 1, then check if they also appear on day 2. Compute the ratio of users in both days to users on day 1.

4. Validate and handle edge cases

Check for duplicate events, bot traffic, and time zone consistency. Consider if users must be active on both days or if any click on day 2 counts. Also, decide how to handle users with no activity on day 2 (they count as not retained).

5. Interpret and communicate results

Present the retention rate as a percentage, and discuss potential business implications (e.g., engagement, product changes). Mention any caveats or limitations of the analysis.

Key Points to Mention

  • Definition of 'shopping click' and how to filter for it in the data.
  • User-level aggregation: counting unique users, not total clicks.
  • Denominator: users with at least one shopping click on 2025-08-31.
  • Numerator: users from denominator who also had at least one shopping click on 2025-09-01.
  • Time zone considerations: ensure both days are in the same time zone (e.g., UTC or PT).
  • Potential data quality issues: bots, duplicate events, or incomplete data.

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

Q3

For the 7-day window ending 2025-09-01, return each user's top 2 pins by deduplicated shopping click count, with ties broken by total positive stay time and then by smallest pin ID.

Data ModelingProduct Analytics & Metrics
Author's notes

The tie-breaking chain is what gets you.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the definitions of 'shopping click' and 'positive stay time' and confirm the date window boundaries. Then, write a SQL query that aggregates deduplicated clicks per user-pin, ranks pins using the specified tie-breakers, and filters to the top 2 per user. Finally, validate the results with edge cases like ties and missing data.

Pro tip: Explicitly state your assumptions about deduplication (e.g., unique user-pin-day) and tie-breaking order, as these details are often ambiguous and can significantly impact results. Also, mention how you would handle users with fewer than 2 pins.

1. Clarify Definitions and Scope

Confirm what constitutes a 'shopping click' (e.g., event type) and 'positive stay time' (e.g., time spent > 0). Verify the 7-day window: 2025-08-26 to 2025-09-01 inclusive.

2. Aggregate Metrics per User-Pin

Compute deduplicated shopping click count (e.g., count distinct click IDs or user-pin-day combinations) and total positive stay time for each user-pin pair within the window.

3. Rank Pins with Tie-Breakers

Use a window function (e.g., ROW_NUMBER) partitioned by user, ordered by click count DESC, stay time DESC, and pin ID ASC to assign ranks.

4. Filter Top 2 and Validate

Select ranks 1 and 2 per user. Validate results by checking for ties, ensuring correct ordering, and handling users with fewer than 2 pins.

Key Points to Mention

  • Deduplication logic: define what constitutes a duplicate click (e.g., same user, pin, and timestamp) and use COUNT(DISTINCT) or equivalent.
  • Date window: use inclusive boundaries and ensure timezone consistency (e.g., UTC).
  • Tie-breaking order: click count DESC, then stay time DESC, then pin ID ASC.
  • Use of window functions (ROW_NUMBER, RANK, DENSE_RANK) and why ROW_NUMBER is appropriate for deterministic top-N.
  • Handling users with fewer than 2 pins: include them with available pins or exclude based on business need.
  • Performance considerations: partition and index on user_id and date for efficient aggregation.

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

Q4

In pandas, map product category codes to names using a provided dictionary so that any missing or unrecognized codes fall back to 'Unknown', replace negative stay_time_sec values with NaN, fill remaining NaN stay times with 0 for aggregation while still excluding zeros from averages, sort the DataFrame by user ID ascending then event timestamp and stay time descending, and finally compute each user's top product category by total positive stay time over the last 7 days with alphabetical tie-breaking.

Product Analytics & MetricsData Modeling
Author's notes

Four sub-tasks rolled into one and they all interact.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Break the problem into clear stages: data cleaning (mapping, handling negatives, filling NaNs), sorting, and aggregation. For the final metric, filter to the last 7 days and positive stay times, then group by user and category to compute total stay time, and select the top category per user with alphabetical tie-breaking. Use pandas operations like map, replace, fillna, sort_values, groupby, and idxmax or nlargest with careful handling of ties.

Pro tip: When computing averages that exclude zeros, use a masked groupby (e.g., df[df.stay_time_sec > 0].groupby('user_id').mean()) rather than filling zeros and then filtering, to avoid skewing results. Also, for tie-breaking alphabetically, sort categories ascending before using idxmax to ensure deterministic selection.

1. Map and clean data

Use df['category'].map(category_dict).fillna('Unknown') to map codes to names and handle missing codes. Replace negative stay_time_sec with NaN using df.loc[df.stay_time_sec < 0, 'stay_time_sec'] = np.nan.

2. Fill NaNs and sort

Fill remaining NaN stay_time_sec with 0 for aggregation. Sort the DataFrame by user_id ascending, timestamp ascending, and stay_time_sec descending using df.sort_values(by=['user_id', 'timestamp', 'stay_time_sec'], ascending=[True, True, False]).

3. Filter for last 7 days and positive stays

Determine the reference date (e.g., max timestamp) and filter to events within the last 7 days. Also filter to stay_time_sec > 0 to exclude zeros from averages and totals.

4. Aggregate and select top category

Group by user_id and category, sum stay_time_sec, then for each user select the category with the highest total. For ties, sort categories alphabetically and pick the first.

Key Points to Mention

  • Use of map with a dictionary and fillna for fallback to 'Unknown'.
  • Handling negative values by converting to NaN, then filling with 0 for aggregation but excluding zeros from averages.
  • Sorting with multiple keys and mixed ascending/descending order.
  • Filtering to the last 7 days based on a reference date (e.g., max timestamp or current date).
  • Grouping and aggregating with sum, then selecting top category per user with tie-breaking.
  • Ensuring deterministic tie-breaking by sorting categories alphabetically before selection.

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