Low-Quality Problems - Problem
You're working as a data analyst for a coding practice platform and need to identify which problems are performing poorly based on user feedback.
Given a Problems table that tracks user engagement for each coding problem:
| Column Name | Type |
|---|---|
| problem_id | int |
| likes | int |
| dislikes | int |
Your task is to find all low-quality problems where the like percentage is strictly less than 60%.
Like Percentage Formula: likes / (likes + dislikes) * 100
Return the problem_id of all low-quality problems ordered by problem_id in ascending order.
Example: If a problem has 3 likes and 7 dislikes, the like percentage is 3/(3+7) = 30%, which is less than 60%, so it's low-quality.
Input & Output
example_1.sql โ Basic Case
$
Input:
Problems table:
| problem_id | likes | dislikes |
|------------|-------|----------|
| 6 | 1748 | 2205 |
| 7 | 2519 | 1086 |
| 8 | 3547 | 2538 |
โบ
Output:
| problem_id |
|------------|
| 6 |
| 8 |
๐ก Note:
Problem 6: 1748/(1748+2205) = 44.2% < 60% (low-quality). Problem 7: 2519/(2519+1086) = 69.9% โฅ 60% (good quality). Problem 8: 3547/(3547+2538) = 58.3% < 60% (low-quality). Results are ordered by problem_id.
example_2.sql โ Edge Case
$
Input:
Problems table:
| problem_id | likes | dislikes |
|------------|-------|----------|
| 1 | 3 | 2 |
| 2 | 6 | 4 |
| 3 | 1 | 1 |
โบ
Output:
| problem_id |
|------------|
| 3 |
๐ก Note:
Problem 1: 3/(3+2) = 60% โฅ 60% (not low-quality). Problem 2: 6/(6+4) = 60% โฅ 60% (not low-quality). Problem 3: 1/(1+1) = 50% < 60% (low-quality). Only problem 3 qualifies.
example_3.sql โ All Low Quality
$
Input:
Problems table:
| problem_id | likes | dislikes |
|------------|-------|----------|
| 10 | 1 | 9 |
| 5 | 2 | 8 |
| 15 | 0 | 1 |
โบ
Output:
| problem_id |
|------------|
| 5 |
| 10 |
| 15 |
๐ก Note:
Problem 10: 1/(1+9) = 10% < 60%. Problem 5: 2/(2+8) = 20% < 60%. Problem 15: 0/(0+1) = 0% < 60%. All problems are low-quality, sorted by problem_id: [5, 10, 15].
Constraints
- 1 โค problem_id โค 105
- 0 โค likes, dislikes โค 105
- likes + dislikes > 0 (each problem has at least one vote)
- The result should be ordered by problem_id in ascending order
Visualization
Tap to expand
Understanding the Visualization
1
Input Data
Each problem has likes and dislikes from user feedback
2
Calculate Total
Add likes + dislikes to get total votes for each problem
3
Find Percentage
Divide likes by total votes to get like percentage
4
Apply Threshold
Keep only problems where like percentage < 60%
5
Sort Results
Order qualifying problem IDs in ascending order
Key Takeaway
๐ฏ Key Insight: This problem demonstrates how SQL can efficiently filter data using mathematical operations in WHERE clauses, making it perfect for percentage-based quality assessments.
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code