LeetCode 1633: Percentage of Users Attended a Contest
LeetCode 1633 Solution 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)
:
LeetCode 1633 Solutions in Java, C++, Python
# 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;
Interactive Code Editor for LeetCode 1633
Improve Your LeetCode 1633 Solution
Use the editor below to refine the provided solution for LeetCode 1633. Select a programming language and try the following:
- Add import statements if required.
- Optimize the code for better time or space complexity.
- Add test cases to validate edge cases and common scenarios.
- Handle error conditions or invalid inputs gracefully.
- Experiment with alternative approaches to deepen your understanding.
Click "Run Code" to execute your solution and view the output. If errors occur, check the line numbers and debug accordingly. Resize the editor by dragging its bottom edge.
Loading editor...