Low-Quality Problems - Problem

You are given a table Problems that contains information about LeetCode problems, including the number of likes and dislikes for each problem.

Table: Problems

Column NameType
problem_idint
likesint
dislikesint

In SQL, problem_id is the primary key column for this table. Each row of this table indicates the number of likes and dislikes for a LeetCode problem.

Task: Find the IDs of the low-quality problems. A LeetCode problem is low-quality if the like percentage of the problem (number of likes divided by the total number of votes) is strictly less than 60%.

Return the result table ordered by problem_id in ascending order.

Table Schema

Problems
Column Name Type Description
problem_id PK int Unique identifier for each problem
likes int Number of likes for the problem
dislikes int Number of dislikes for the problem
Primary Key: problem_id
Note: Each row represents a LeetCode problem with its vote statistics

Input & Output

Example 1 — Mixed Quality Problems
Input Table:
problem_id likes dislikes
6 1290 425
11 2677 8659
7 24 40
Output:
problem_id
7
11
💡 Note:

Problem 6: Like percentage = 1290/(1290+425) = 1290/1715 ≈ 75.2% → Not low-quality (≥ 60%)

Problem 7: Like percentage = 24/(24+40) = 24/64 = 37.5% → Low-quality (< 60%)

Problem 11: Like percentage = 2677/(2677+8659) = 2677/11336 ≈ 23.6% → Low-quality (< 60%)

Results are ordered by problem_id: [7, 11]

Example 2 — All High Quality
Input Table:
problem_id likes dislikes
1 100 50
2 200 100
Output:
problem_id
💡 Note:

Problem 1: Like percentage = 100/(100+50) = 100/150 ≈ 66.7% → Not low-quality

Problem 2: Like percentage = 200/(200+100) = 200/300 ≈ 66.7% → Not low-quality

No problems have like percentage < 60%, so result is empty.

Example 3 — Boundary Case
Input Table:
problem_id likes dislikes
5 60 40
8 59 41
Output:
problem_id
8
💡 Note:

Problem 5: Like percentage = 60/(60+40) = 60/100 = 60.0% → Not low-quality (exactly 60%)

Problem 8: Like percentage = 59/(59+41) = 59/100 = 59.0% → Low-quality (< 60%)

Only problem 8 is strictly less than 60%.

Constraints

  • 1 ≤ problem_id ≤ 100
  • 0 ≤ likes ≤ 100
  • 0 ≤ dislikes ≤ 100
  • likes + dislikes > 0

Visualization

Tap to expand
Low-Quality Problems Filter problems with like percentage < 60% INPUT ID Likes Dislikes 1 100 50 2 40 80 3 200 100 4 30 70 5 60 40 problems table Quality Formula: likes / (likes + dislikes) Threshold: 60% (0.6) ALGORITHM STEPS 1 Calculate Total Votes total = likes + dislikes 2 Compute Like Ratio ratio = likes / total 3 Filter Low Quality WHERE ratio < 0.6 4 Sort Results ORDER BY problem_id ASC Calculations: ID1: 100/150 = 0.67 OK ID2: 40/120 = 0.33 LOW ID3: 200/300 = 0.67 OK ID4: 30/100 = 0.30 LOW ID5: 60/100 = 0.60 OK FINAL RESULT Low-Quality Problem IDs: 2 4 problem_id [2, 4] 2 problems found with like ratio < 60% SELECT problem_id FROM problems WHERE likes/(likes+dislikes) < 0.6 ORDER BY problem_id Key Insight: The quality threshold is STRICTLY less than 60%, so problems with exactly 60% ratio are NOT considered low-quality. Use integer arithmetic carefully: likes/(likes+dislikes) may need casting to avoid integer division truncation in SQL. TutorialsPoint - Low-Quality Problems | Optimal Solution
Asked in
Facebook 8 Amazon 5 Google 3
27.7K 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