Skip to main content

Low-Quality Problems - Solution & Explanation

EasyPremiumFree on FleetCodeDatabase4 min read
Practice this problem

Problem Statement

Table: Problems

+-------------+------+
| Column Name | Type |
+-------------+------+
| problem_id  | int  |
| likes       | int  |
| dislikes    | int  |
+-------------+------+
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.

 

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.

The result format is in the following example.

 

Example 1:

Input: 
Problems table:
+------------+-------+----------+
| problem_id | likes | dislikes |
+------------+-------+----------+
| 6          | 1290  | 425      |
| 11         | 2677  | 8659     |
| 1          | 4446  | 2760     |
| 7          | 8569  | 6086     |
| 13         | 2050  | 4164     |
| 10         | 9002  | 7446     |
+------------+-------+----------+
Output: 
+------------+
| problem_id |
+------------+
| 7          |
| 10         |
| 11         |
| 13         |
+------------+
Explanation: The like percentages are as follows:
- Problem 1: (4446 / (4446 + 2760)) * 100 = 61.69858%
- Problem 6: (1290 / (1290 + 425)) * 100 = 75.21866%
- Problem 7: (8569 / (8569 + 6086)) * 100 = 58.47151%
- Problem 10: (9002 / (9002 + 7446)) * 100 = 54.73006%
- Problem 11: (2677 / (2677 + 8659)) * 100 = 23.61503%
- Problem 13: (2050 / (2050 + 4164)) * 100 = 32.99002%
Problems 7, 10, 11, and 13 are low-quality problems because their like percentages are less than 60%.

Approach Overview

Problem Overview: The table Problems stores the number of likes and dislikes for each problem. A problem is considered low quality if its like ratio is below 0.6. The task is to return the problem_id of every problem where likes / (likes + dislikes) < 0.6.

Approach 1: Direct Ratio Filter (O(n) time, O(1) space)

The most direct solution computes the like ratio for every row and filters the rows where the ratio is below 0.6. In SQL, iterate through the table with a simple SELECT query and apply the condition likes / (likes + dislikes) < 0.6 inside the WHERE clause. The database engine performs a linear scan of the table and evaluates the ratio for each record.

This works because each row already contains all the required information. No joins, grouping, or window functions are required. The query simply performs arithmetic and filtering. The time complexity is O(n) since every row is checked once, and the space complexity is O(1) because no additional structures are created.

This approach is the most readable and commonly used in SQL interview questions. It clearly communicates the business rule: identify rows where the like ratio falls below the quality threshold.

Approach 2: Cross-Multiplication Comparison (O(n) time, O(1) space)

Instead of performing division, you can transform the ratio condition mathematically. The expression likes / (likes + dislikes) < 0.6 can be rewritten as likes < 0.6 * (likes + dislikes). This avoids explicit division and relies only on multiplication and comparison.

Many SQL engineers prefer this pattern when dealing with ratios because it avoids potential floating‑point precision issues. The query still scans the table once and evaluates the inequality for each row. The complexity remains O(n) time and O(1) space.

This technique is common in database filtering tasks where ratios or percentages determine eligibility. Transforming the equation makes the query easier for some query planners to optimize and can be slightly more robust when dealing with numeric types.

Recommended for interviews: Use the direct ratio filter first because it clearly expresses the requirement and shows you understand the problem statement. If the interviewer asks about numeric precision or query optimization, mention the cross‑multiplication alternative. Demonstrating both approaches shows comfort with SQL arithmetic and filtering logic in real production queries.

Solution

Code

MySQL

Try this approach in the editor →

Detailed Complexity Analysis

ApproachTimeSpaceWhen to Use
Direct Ratio FilterO(n)O(1)Best for readability when directly applying the ratio condition in SQL
Cross-Multiplication ComparisonO(n)O(1)Useful when avoiding floating point division or improving numeric stability

Video Solution

My Brain after 569 Leetcode Problems • NeetCode • 2,927,647 views views

Watch 9 more video solutions →

Frequently Asked Questions

Is Low-Quality Problems easy or hard?
Low-Quality Problems is classified as Easy. The task only requires understanding a simple ratio condition and applying it in a SQL WHERE clause, making it a straightforward database filtering problem.
Low-Quality Problems Python/Java solution
This is a database problem, so the expected solution is written in SQL rather than Python or Java. In interview settings, you typically write a MySQL query that filters rows based on the computed like ratio.
How to solve Low-Quality Problems in O(n)?
Use a single SQL SELECT statement with a WHERE clause that checks likes / (likes + dislikes) < 0.6. The database engine evaluates the condition for each row during a table scan, producing an O(n) solution with constant extra space.
What is the best approach for Low-Quality Problems?
The best approach is a SQL filter that checks whether the like ratio is below 0.6. Compute the ratio using likes / (likes + dislikes) and return rows where the result is less than 0.6. The query performs a single table scan with O(n) time and O(1) space.
Is Low-Quality Problems asked at Google/Amazon/Meta?
This problem represents a common SQL filtering pattern used in data analysis and backend reporting tasks. Variations of ratio-based filtering frequently appear in database interviews at companies like Amazon, Google, and Meta when testing practical SQL skills.
What data structure is used in Low-Quality Problems?
The problem operates directly on a relational database table. No additional data structures are required because the solution relies on SQL arithmetic expressions and row filtering within the table.
What is the time complexity of Low-Quality Problems?
The time complexity is O(n) because the database scans every row in the Problems table to evaluate the ratio condition. Space complexity is O(1) since the query only filters rows and does not store additional data structures.

Ready to solve this problem?

Practice Low-Quality Problems with our built-in code editor and test cases.

Practice on FleetCode