← Pinterest Interview Insights
Knew right away I needed a rank or dense_rank over a count grouped by country and category.
Start by clarifying the schema and defining 'today' and 'impressions' precisely. Then write a SQL query that joins the tables, filters for today's impressions, aggregates counts by country and pin category, and uses a window function to rank categories within each country, returning all top-ranked categories to handle ties.
Pro tip: Explicitly state your assumptions about the data model (e.g., whether pin_info contains category, how impressions link to pins) and mention that you would validate the results with a quick sanity check, such as ensuring the sum of impressions per country matches the total. This shows you think about data quality and edge cases.
Confirm the columns in each table, how they join (e.g., impression.pin_id = pin_info.pin_id), and define 'today' (e.g., date = CURRENT_DATE) and 'impression' (e.g., event_type = 'impression').
Filter impressions for today, join with pin_info to get category, and group by country and category to count impressions.
Use a window function like RANK() or DENSE_RANK() over (PARTITION BY country ORDER BY impression_count DESC) to assign ranks.
Filter for rank = 1 to return all categories with the highest impression count per country, ensuring ties are included.
Check for nulls, countries with no impressions, and verify that the sum of impressions per country matches the total; discuss how to handle ties in the output.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.
This one took me longer than it should have.
Start by defining the base population: users with at least one impression in the last 7 days per country. Then, for each user, compute two metrics: distinct active days and, for each active day, the number of distinct surfaces used. Identify highly active users as those with >=4 active days and at least one day with >=3 distinct surfaces. Finally, calculate the percentage of highly active users within the active user base for each country.
Pro tip: Clarify the time window: 'last 7 days' should be relative to the analysis date, and ensure you handle users with no activity correctly. Also, consider using a single SQL query with CTEs for efficiency and readability.
Filter the impressions table to the last 7 days and identify users with at least one impression per country. This forms the denominator.
For each user and each active day, count the number of distinct surfaces they used. This will be used to check the '3 or more surfaces on at least one day' condition.
For each user, count distinct active days (must be >=4) and check if any day has >=3 distinct surfaces. Flag users meeting both criteria as highly active.
For each country, compute the ratio of highly active users to total active users, and multiply by 100 to get the percentage.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.