Leetcode Problem 1811. Find Interview Candidates

1811. Find Interview Candidates

Leetcode Solutions

MySQL window function solution

  1. Use UNION ALL to combine gold_medal, silver_medal, and bronze_medal into a single column named user along with their corresponding contest_id.
  2. Apply the ROW_NUMBER() window function partitioned by user and ordered by contest_id to assign a rank to each medal.
  3. Calculate the difference between contest_id and the rank to identify consecutive medals.
  4. Group by user and the calculated difference to find users with three or more consecutive medals.
  5. Separately, group by gold_medal to find users with three or more gold medals.
  6. Use UNION ALL to combine the results from steps 4 and 5.
  7. Join the result with the Users table to get the name and mail of the interview candidates.
  8. Use DISTINCT to remove any duplicates resulting from the union operation.
erDiagram
    Contests {
        int contest_id PK
        int gold_medal
        int silver_medal
        int bronze_medal
    }
    Users {
        int user_id PK
        varchar mail
        varchar name
    }
    Contests ||--o{ Users : "contains"

MySQL self-join and aggregation solution

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...