The Get Highest Answer Rate Question coding problem is a SQL task. You are given a SurveyLog table containing logs of user actions on survey questions. The actions can be "show", "answer", or "skip". You need to find the question_id that has the highest "answer rate". The answer rate is defined as the number of times a question was answered divided by the number of times it was shown.
Meta (Facebook) uses this Database interview pattern to test a candidate's ability to pivot and aggregate event logs. It evaluates your skills in conditional aggregation (using SUM with CASE WHEN or boolean logic) and calculating ratios. Handling edge cases where questions might be shown but never answered, or handling ties, is critical for real-world telemetry analysis.
This problem requires Conditional Aggregation and Sorting.
question_id.action = 'show'.action = 'answer'.question_id ascending).Table:
Aggregation:
1.0 or CAST to a decimal before dividing.NULLIF(shows, 0) is a safe practice.COUNT(*) instead of selectively counting based on the action column.Master the SUM(IF(condition, 1, 0)) or SUM(CASE WHEN condition THEN 1 ELSE 0 END) syntax. It is the most versatile way to count specific events within a grouped dataset without needing multiple complex subqueries.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Apples & Oranges | Medium | Solve | |
| Customers Who Bought Products A and B but Not C | Medium | Solve | |
| Page Recommendations | Medium | Solve | |
| Project Employees III | Medium | Solve | |
| Reported Posts II | Medium | Solve |