
Everyone in the top three
mediumEveryone in the top three
DraftKings SQL Interview Question
DraftKings pays the top three places in a contest, and any lineup tied into those places gets paid too. Cutting the list off at exactly three rows would drop a player who scored the same as somebody who was paid, which is the fastest way to lose a user for good.
Return the contest_id, the user_id, and the points of every entry finishing in the top three places, counting ties as sharing a place.
Asked of
- Data Analyst
- Business Analyst
- BI Analyst
- Product Analyst
- Analytics Engineer
- Data Engineer
- Data Scientist
draftkings_contest_entriesTable28 rows
| Column Name | Type |
|---|---|
| entry_id | BIGINT |
| contest_id | VARCHAR |
| user_id | VARCHAR |
| joined_at | TIMESTAMP |
| points | DOUBLE |
draftkings_contest_entriesExample Input
| entry_id | contest_id | user_id | joined_at | points |
|---|---|---|---|---|
| 3101 | C1 | U100 | 2024-03-20 18:05:00 | 742.5 |
| 3102 | C1 | U101 | 2024-03-20 18:11:00 | 801 |
| 3103 | C1 | U102 | 2024-03-20 18:14:00 | 801 |
| 3104 | C1 | U103 | 2024-03-20 18:22:00 | 689.5 |
| 3105 | C1 | U104 | 2024-03-20 18:30:00 | 742.5 |
| 3106 | C1 | U105 | 2024-03-20 18:41:00 | 655 |
| 3107 | C1 | U106 | 2024-03-20 18:52:00 | 812.5 |
| 3120 | C4 | U100 | 2024-03-23 17:30:00 | 455.5 |
| 3121 | C4 | U107 | 2024-03-23 17:38:00 | 455.5 |
| 3122 | C4 | U108 | 2024-03-23 17:49:00 | 603 |
| 3123 | C4 | U110 | 2024-03-23 17:55:00 | 588.5 |
| 3124 | C4 | U111 | 2024-03-23 18:04:00 | 721.5 |
Example Output
| contest_id | user_id | points |
|---|---|---|
| C1 | U101 | 801 |
| C1 | U102 | 801 |
| C1 | U106 | 812.5 |
| C4 | U108 | 603 |
| C4 | U110 | 588.5 |
| C4 | U111 | 721.5 |
Explanation
C1 has one lineup in first and two tied in second, and those three fill all three paid places. The two on 742.5 are fourth, not third, because the tie above them used up a place, so they are not paid.
The example above is a small slice of the data. Your query runs against the full tables.
Company
DraftKings
Difficulty
medium
Topic
ranking
Language
SQL
Your query
Starting the SQL engine...