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.Input FormatThe following tables contain contest data:Hackers: The hacker_id is the id of the hacker, and name is the name of the hacker. Difficulty: The difficult_level is the level of difficulty of the challenge, and score is the score of the challenge for the difficulty level. 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. 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. Sample InputHackers Table: Difficulty Table: Challenges Table: Submissions Table: Sample Output
Question
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.Input FormatThe following tables contain contest data:Hackers: The hacker_id is the id of the hacker, and name is the name of the hacker. Difficulty: The difficult_level is the level of difficulty of the challenge, and score is the score of the challenge for the difficulty level. 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. 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. Sample InputHackers Table: Difficulty Table: Challenges Table: Submissions Table: Sample Output
Solution
It seems like you're asking for a SQL query to solve this problem. Here's a step-by-step solution:
-
First, we need to join the tables. We'll join the
Submissionstable with theChallengestable onchallenge_id, and then join this with theDifficultytable ondifficulty_level. This will give us a table that includes each submission, the challenge it belongs to, and the maximum score for that challenge's difficulty level. -
Next, we'll filter this table to only include submissions where the score is equal to the maximum score for that challenge's difficulty level. This will give us a table of all the submissions where the hacker achieved a full score.
-
Then, we'll group this table by
hacker_idand count the number of full score submissions for each hacker. -
Finally, we'll filter this table to only include hackers who achieved full scores for more than one challenge, and order the results as specified.
Here's what the SQL query might look like:
SELECT h.hacker_id, h.name
FROM Hackers h
JOIN (
SELECT s.hacker_id, COUNT(*) as full_score_count
FROM Submissions s
JOIN Challenges c ON s.challenge_id = c.challenge_id
JOIN Difficulty d ON c.difficulty_level = d.difficulty_level
WHERE s.score = d.score
GROUP BY s.hacker_id
HAVING COUNT(*) > 1
) fs ON h.hacker_id = fs.hacker_id
ORDER BY fs.full_score_count DESC, h.hacker_id ASC;
This query first creates a subquery (fs) that counts the number of full score submissions for each hacker, and then joins this with the Hackers table to get the hacker names. The HAVING clause in the subquery is used to only include hackers with more than one full score submission. The final results are ordered by the number of full score submissions in descending order, and then by hacker_id in ascending order.
Similar Questions
You did such a great job helping Julia with her last coding contest challenge that she wants you to work on this one, too!The total score of a hacker is the sum of their maximum scores for all of the challenges. Write a query to print the hacker_id, name, and total score of the hackers ordered by the descending score. If more than one hacker achieved the same total score, then sort the result by ascending hacker_id. Exclude all hackers with a total score of from your result.Input FormatThe following tables contain contest data:Hackers: The hacker_id is the id of the hacker, and name is the name of the hacker. 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 for which the submission belongs to, and score is the score of the submission. Sample InputHackers Table: Submissions Table: Sample Output4071 Rose 19174842 Lisa 17484072 Bonnie 1004806 Angela 8926071 Frank 8580305 Kimberly 6749438 Patrick 43ExplanationHacker 4071 submitted solutions for challenges 19797 and 49593, so the total score .Hacker 74842 submitted solutions for challenges 19797 and 63132, so the total score Hacker 84072 submitted solutions for challenges 49593 and 63132, so the total score .The total scores for hackers 4806, 26071, 80305, and 49438 can be similarly calculated.
Julia asked her students to create some coding challenges. Write a query to print the hacker_id, name, and the total number of challenges created by each student. Sort your results by the total number of challenges in descending order. If more than one student created the same number of challenges, then sort the result by hacker_id. If more than one student created the same number of challenges and the count is less than the maximum number of challenges created, then exclude those students from the result.Input FormatThe following tables contain challenge data:Hackers: The hacker_id is the id of the hacker, and name is the name of the hacker. Challenges: The challenge_id is the id of the challenge, and hacker_id is the id of the student who created the challenge.
select h.hacker_id,h.name,sum(max(s.score)) from hackers h JOIN submissions s ON h.hacker_id=s.hacker_idgroup by h.hacker_idhaving sum(max(s.score)>0 order by sum(max(s.score) desc,h.hacker_id;
In a coding contest, there are prizes for the top rankers. The prize scheme is as follows:Top 1010 participants receive rupees 𝑋X each.Participants with rank 1111 to 100100 (both inclusive) receive rupees 𝑌Y each.Find the total prize money over all the contestants.Input FormatFirst line will contain 𝑇T, number of test cases. Then the test cases follow.Each test case contains of a single line of input, two integers 𝑋X and 𝑌Y - the prize for top 1010 rankers and the prize for ranks 1111 to 100100 respectively.Output FormatFor each test case, output the total prize money over all the contestants.Constraints1≤𝑇≤10001≤T≤10001≤𝑌≤𝑋≤10001≤Y≤X≤1000Sample 1:InputOutput41000 1001000 100080 1400 30190001000008906700Explanation:Test Case 11: Top 1010 participants receive rupees 10001000 and next 9090 participants receive rupees 100100 each. So, total prize money =10⋅1000+90⋅100=19000=10⋅1000+90⋅100=19000.Test Case 22: Top 1010 participants receive rupees 10001000 and next 9090 participants receive rupees 10001000 each. So, total prize money =10⋅1000+90⋅1000=100000=10⋅1000+90⋅1000=100000.Test Case 33: Top 1010 participants receive rupees 8080 and next 9090 participants receive rupee 11 each. So, total prize money =10⋅80+90⋅1=890=10⋅80+90⋅1=890.Test Case 44: Top 1010 participants receive rupees 400400 and next 9090 participants receive rupees 3030 each. So, total prize money =10⋅400+90⋅30=6700=10⋅400+90⋅30=6700.
Problem StatementIn a gaming tournament, players are ranked in ascending order based on their scores. Your task is to design a program using binary search to determine the score of the player positioned at the kth place, enabling the organizers to swiftly identify individual performance levels. The program takes the total number of players, their sorted scores, and the rank (k) as input, and outputs the score of the player ranked at the kth position(position value starts from 1).Input format :The first line of input consists of an integer N, representing the total number of players in the tournament.The second line consists of N distinct space-separated integers, representing the sorted list of players' scores.The third line consists of an integer k, representing the rank of the player whose score needs to be determined.Output format :The output prints a single integer, representing the score of the player ranked at position k in the tournament.Code constraints :1 ≤ N ≤ 101 ≤ score ≤ 1001 ≤ k ≤ NSample test cases :Input 1 :712 15 34 47 49 57 583Output 1 :34Input 2 :624 25 37 48 98 995Output 2 :98
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.