LeetCode 1633: Percentage of Users Attended a Contest Solution
Master LeetCode problem 1633 (Percentage of Users Attended a Contest), 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.
1633. Percentage of Users Attended a Contest
Problem Explanation
Explanation:
- Calculate the total number of users registered in each contest.
- Calculate the total number of users in the Users table.
- Compute the percentage of users registered in each contest.
- Return the result table sorted by percentage in descending order. In case of a tie, order by contest_id in ascending order.
Time Complexity: O(nlogn) where n is the number of records in the Register table
Space Complexity: O(n)
:
Solution Code
# Write your Java solution here
SELECT contest_id,
ROUND(COUNT(user_id) * 100.0 / (SELECT COUNT(DISTINCT user_id) FROM Register), 2) AS percentage
FROM Register
GROUP BY contest_id
ORDER BY percentage DESC, contest_id;Try It Yourself
Loading code editor...
Related LeetCode Problems
Frequently Asked Questions
How to solve LeetCode 1633 (Percentage of Users Attended a Contest)?
This page provides optimized solutions for LeetCode problem 1633 (Percentage of Users Attended a Contest) 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 1633 (Percentage of Users Attended a Contest)?
The time complexity for LeetCode 1633 (Percentage of Users Attended a Contest) varies by solution. Check the detailed explanation section for specific complexities in Java, C++, and Python implementations.
Can I run code for LeetCode 1633 on DevExCode?
Yes, DevExCode provides an interactive code editor where you can write, test, and run your code for LeetCode 1633 in Java, C++, or Python.