LeetCode 1211: Queries Quality and Percentage Solution
Master LeetCode problem 1211 (Queries Quality and Percentage), a easy challenge, with our optimized solutions in Java, C++, and Python. Explore detailed explanations, test your code in our interactive editor, and prepare for coding interviews.
1211. Queries Quality and Percentage
Problem Explanation
Explanation:
To solve this problem, we need to calculate the quality and poor query percentage for each distinct query name based on the given formulas. We can achieve this by grouping the data by query name, calculating the required values, and then formatting the output accordingly.
- Initialize a temporary table to store the sum of ratings divided by positions and the count of poor queries for each query name.
- Calculate the quality for each query by summing up the ratio of rating to position for each row and then dividing by the total count of rows for that query.
- Calculate the poor query percentage for each query by counting the number of rows with a rating less than 3 and dividing by the total count of rows for that query.
- Round the quality and poor query percentage to 2 decimal places.
- Return the query name, quality, and poor query percentage in the desired output format.
Time Complexity: O(n) where n is the number of rows in the input table. Space Complexity: O(n) for storing the temporary table data.
:
Solution Code
# Write your Java solution here
SELECT query_name,
ROUND(SUM(CAST(rating AS DECIMAL) / position) / COUNT(*), 2) AS quality,
ROUND((SUM(CASE WHEN rating < 3 THEN 1 ELSE 0 END) / COUNT(*)) * 100, 2) AS poor_query_percentage
FROM Queries
GROUP BY query_name;Try It Yourself
Loading code editor...
Related LeetCode Problems
Frequently Asked Questions
How to solve LeetCode 1211 (Queries Quality and Percentage)?
This page provides optimized solutions for LeetCode problem 1211 (Queries Quality and Percentage) in Java, C++, and Python, along with a detailed explanation and an interactive code editor to test your code.
What is the time complexity of LeetCode 1211 (Queries Quality and Percentage)?
The time complexity for LeetCode 1211 (Queries Quality and Percentage) varies by solution. Check the detailed explanation section for specific complexities in Java, C++, and Python implementations.
Can I run code for LeetCode 1211 on DevExCode?
Yes, DevExCode provides an interactive code editor where you can write, test, and run your code for LeetCode 1211 in Java, C++, or Python.