Weekly Suggestion Acceptance Rate by Category From Raw Events
Last updated: November 29, 2026
Quick Overview
Given an event table where each suggestion can be logged as shown (possibly many times), accepted, or dismissed, write a SQL query that returns, for each week and suggestion category, the number of distinct suggestions shown, the number accepted, and the acceptance rate.
Grammarly
November 29, 20260
0
0 solved
Given an event table where each suggestion can be logged as shown (possibly many times), accepted, or dismissed, write a SQL query that returns, for each week and suggestion category, the number of distinct suggestions shown, the number accepted, and the acceptance rate.
Acceptance rate per category is one of the basic health metrics for Grammarly's suggestions, and the raw logs are noisy (cards re-render, users click twice). The interviewer checks deduplication, the right denominator, and a LEFT JOIN that keeps zero-acceptance groups.
What the Interviewer Expects
- Deduplicate repeated shown and accepted events to one per suggestion
- Assign each suggestion to a single week (first impression) so it is not double counted
- Use a LEFT JOIN so categories with no accepts still appear
- Avoid integer division when computing the rate
- Sanity-check results on a tiny hand-made table
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you make this a per-user average instead of a pooled rate, and when would that be preferred?
- An accept can happen days after the impression. How would you window it?
- How would you exclude suggestions that were shown but never visible on screen?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
Table suggestion_events(event_id, user_id, suggestion_id, category, event_type, event_ts) with event_type in shown, accepted, dismissed. One suggestion_id is one underline instance. I assu...
Approach
Collapse impressions to one row per suggestion with its first shown week. Separately collect the distinct set of accepted suggestion ids. LEFT JOIN accepted onto shown and aggregate by week and catego...