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 NameType
problem_idint
likesint
dislikesint

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
Low-Quality Problems DetectionProblem DataID: 6๐Ÿ‘ 1748 likes๐Ÿ‘Ž 2205 dislikesTotal: 3953 votesCalculate %1748 รท 3953= 0.442= 44.2%Check Threshold44.2% < 60%?โœ“ YESLow Quality!ResultInclude ID: 6โœ“ AddedComplete Example WalkthroughProblem 61748 likes, 2205 dislikes44.2% < 60% โŒโ†’ IncludeProblem 72519 likes, 1086 dislikes69.9% โ‰ฅ 60% โœ“โ†’ SkipProblem 83547 likes, 2538 dislikes58.3% < 60% โŒโ†’ IncludeFinal SQL QuerySELECT problem_id FROM ProblemsWHERE likes / (likes + dislikes) < 0.6ORDER BY problem_id ASC;Result: [6, 8]
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.
Asked in
Amazon 15 Google 12 Meta 8 Microsoft 6
23.5K Views
Medium Frequency
~8 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
๐Ÿ’ก Explanation
AI Ready
๐Ÿ’ก Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen