Anusha Murali

Logo

Please see github.com/anusha-murali for all of my repositories.

View GitHub Profile

44. Top Competitors: Solution


Julia just finished conducting a coding contest, and she needs your help assembling the leaderboard! Write a query to print the respective hacker_id and name of hackers who achieved full scores for more than one challenge. Order your output in descending order by the total number of challenges in which the hacker earned a full score. If more than one hacker received full scores in same number of challenges, then sort them by ascending hacker_id.

The following tables contain contest data:

HACKERS: The hacker_id is the id of the hacker, and name is the name of the hacker.

44_1

DIFFICULTY: The difficult_level is the level of difficulty of the challenge, and score is the score of the challenge for the difficulty level.

44_2

CHALLENGES: The challenge_id is the id of the challenge, the hacker_id is the id of the hacker who created the challenge, and difficulty_level is the level of difficulty of the challenge.

44_3

SUBMISSIONS: The submission_id is the id of the submission, hacker_id is the id of the hacker who made the submission, challenge_id is the id of the challenge that the submission belongs to, and score is the score of the submission.

44_4

Sample Input

44_5

44_6

44_7

44_8

Sample Output

90411 Joe

Explanation

Hacker 86870 got a score of 30 for challenge 71055 with a difficulty level of 2, so 86870 earned a full score for this challenge.

Hacker 90411 got a score of 30 for challenge 71055 with a difficulty level of 2, so 90411 earned a full score for this challenge.

Hacker 90411 got a score of 100 for challenge 66730 with a difficulty level of 6, so 90411 earned a full score for this challenge.

Only hacker 90411 managed to earn a full score for more than one challenge, so we print the their hacker_id and name as 2 space-separated values.

solution_image5

SELECT SUBMISSIONS.HACKER_ID, HACKERS.NAME
FROM HACKERS, SUBMISSIONS, CHALLENGES, DIFFICULTY
WHERE SUBMISSIONS.CHALLENGE_ID = CHALLENGES.CHALLENGE_ID AND
      CHALLENGES.DIFFICULTY_LEVEL = DIFFICULTY.DIFFICULTY_LEVEL AND
      DIFFICULTY.SCORE = SUBMISSIONS.SCORE AND
      HACKERS.HACKER_ID = SUBMISSIONS.HACKER_ID
      GROUP BY SUBMISSIONS.HACKER_ID, HACKERS.NAME
      HAVING COUNT(SUBMISSIONS.SCORE) > 1
      ORDER BY COUNT(SUBMISSIONS.SCORE) DESC, HACKER_ID;

Back to problems


anusha-murali.github.io