Find Interview Candidates - Problem

You are given two tables: Contests and Users.

The Contests table contains information about LeetCode contests and their medalists:

  • contest_id: Unique identifier for each contest
  • gold_medal: User ID of the gold medalist
  • silver_medal: User ID of the silver medalist
  • bronze_medal: User ID of the bronze medalist

The Users table contains user information:

  • user_id: Unique identifier for each user
  • mail: User's email address
  • name: User's name

Task: Find all interview candidates. A user qualifies as an interview candidate if:

  1. They won any medal in three or more consecutive contests, OR
  2. They won the gold medal in three or more different contests (not necessarily consecutive)

Return the name and mail of all interview candidates in any order.

Table Schema

Contests
Column Name Type Description
contest_id PK int Unique contest identifier
gold_medal int User ID of gold medalist
silver_medal int User ID of silver medalist
bronze_medal int User ID of bronze medalist
Primary Key: contest_id
Users
Column Name Type Description
user_id PK int Unique user identifier
mail varchar User's email address
name varchar User's name
Primary Key: user_id

Input & Output

Example 1 — Consecutive Medals Winner
Input Tables:
Contests
contest_id gold_medal silver_medal bronze_medal
190 1 2 3
191 1 4 5
192 1 6 7
193 8 9 10
Users
user_id mail name
1 [email protected] Alice
2 [email protected] Bob
8 [email protected] Charlie
Output:
name mail
Alice [email protected]
💡 Note:

Alice (user_id=1) won gold medals in 3 consecutive contests (190, 191, 192), qualifying her as an interview candidate. She also meets the consecutive medal requirement by winning any medal in 3+ consecutive contests.

Example 2 — Multiple Gold Winner
Input Tables:
Contests
contest_id gold_medal silver_medal bronze_medal
190 1 2 3
192 1 4 5
195 1 6 7
200 8 9 10
Users
user_id mail name
1 [email protected] Alice
8 [email protected] Charlie
Output:
name mail
Alice [email protected]
💡 Note:

Alice (user_id=1) won gold medals in 3 different contests (190, 192, 195), qualifying her as an interview candidate based on the gold medal criterion. The contests are not consecutive, but that's not required for gold medal qualification.

Example 3 — No Qualified Candidates
Input Tables:
Contests
contest_id gold_medal silver_medal bronze_medal
190 1 2 3
195 4 5 6
Users
user_id mail name
1 [email protected] Alice
2 [email protected] Bob
Output:
name mail
💡 Note:

No user qualifies as an interview candidate. User 1 won only 1 gold medal (need 3+), and no user won medals in 3+ consecutive contests (only 2 contests total).

Constraints

  • 1 ≤ contest_id ≤ 1000
  • 1 ≤ gold_medal, silver_medal, bronze_medal ≤ 10^6
  • 1 ≤ user_id ≤ 10^6
  • All contest_id values are unique
  • Consecutive contests have consecutive IDs with no gaps

Visualization

Tap to expand
Find Interview Candidates Problem OverviewInput Tablescontestgoldsilverbronze190123191145192167user_idname1AliceAnalysis Criteria1. Any medal in 3+ consecutivecontests (190,191,192) ✓2. Gold medal in 3+ differentcontests ✓OutputnamemailAlice[email protected]User 1 (Alice) qualifies under BOTH criteria!✓ Won medals in 3 consecutive contests (190, 191, 192)✓ Won 3 gold medals in different contests
Understanding the Visualization
1
Input
Contests and Users tables
2
Analysis
Check consecutive medals and gold medal count
3
Output
Qualified candidates
Key Takeaway
🎯 Key Insight: Use UNION to combine multiple qualification criteria efficiently
Asked in
Meta 12 Google 8 Amazon 6
28.5K Views
Medium Frequency
~18 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen