← Pinterest Interview Insights
Start by aggregating total impressions per country and category using GROUP BY. Then use a window function like ROW_NUMBER() or RANK() to identify the top category per country, and finally filter to return only the highest. Alternatively, use a correlated subquery or join with a derived table to get the max count per country.
Pro tip: Mention that you'd handle ties explicitly—either by using RANK() and filtering for rank=1 (which may return multiple rows) or by using ROW_NUMBER() with a deterministic tiebreaker like category name. This shows attention to edge cases and data quality.
Confirm what 'impressions' means (e.g., count of rows or sum of an impressions column) and whether ties should be broken. State any assumptions you make.
Write a subquery or CTE that groups by country and category, summing or counting impressions to get total_impressions.
Use a window function like ROW_NUMBER() or RANK() over (PARTITION BY country ORDER BY total_impressions DESC) to assign a rank to each category.
Select rows where the rank equals 1. If using RANK(), decide how to handle ties (e.g., return all tied categories or pick one arbitrarily).
Show the complete SQL, walk through the logic, and mention any performance considerations or alternative approaches.
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 I'd like to admit.
First, clarify the dataset schema and definitions (e.g., what constitutes an active day and a distinct feature). Then, compute per-user daily aggregates of distinct features, identify heavy users by applying the two conditions (≥4 active days in last 7 days and ≥1 day with ≥3 distinct features), and finally calculate the weekly heavy-user rate as the proportion of heavy users among all users in the week.
Pro tip: Always confirm the time window and whether 'last 7 days' refers to a rolling period or a fixed week; also discuss how to handle edge cases like users with no activity or incomplete data.
Ensure you understand what 'active day' means (e.g., any event) and how to count distinct features. Confirm the time frame: is it a fixed calendar week or a rolling 7-day window?
For each user and day, compute the number of distinct features used. This can be done by grouping by user and date and counting distinct feature IDs.
For each user, check if they have at least 4 active days in the last 7 days and at least one day where distinct features ≥3. Flag them as heavy users.
Divide the number of heavy users by the total number of users active in the week (or all users, depending on definition). Express as a percentage.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.