Sign in with Google

Google will share your name, email, and profile picture with DevExCode. See our privacy policy.

LeetCode 1633: Percentage of Users Attended a Contest

Database

LeetCode 1633 Solution Explanation

Explanation:

  1. Calculate the total number of users registered in each contest.
  2. Calculate the total number of users in the Users table.
  3. Compute the percentage of users registered in each contest.
  4. 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...

Related LeetCode Problems