Accepted Candidates From the Interviews - Problem
You're working for a tech company's HR department that needs to analyze interview results to identify qualified candidates. The company has a structured interview process where candidates go through multiple rounds, and you need to filter candidates based on two key criteria:
- Experience requirement: At least 2 years of professional experience
- Performance threshold: Total interview score must be strictly greater than 15
You have access to two tables:
Candidates- Contains candidate information including their experience and interview IDRounds- Contains individual round scores for each interview
Your task: Write a SQL query to find all candidate IDs who meet both criteria and should be accepted for the position.
The results can be returned in any order.
Input & Output
example_1.sql โ Basic Example
$
Input:
Candidates:
| candidate_id | name | years_of_exp | interview_id |
|--------------|-------|--------------|---------------|
| 11 | Atticus | 1 | 101 |
| 21 | Ruben | 6 | 102 |
| 22 | Aliza | 10 | 103 |
Rounds:
| interview_id | round_id | score |
|--------------|----------|-------|
| 101 | 1 | 8 |
| 101 | 2 | 7 |
| 102 | 1 | 9 |
| 102 | 2 | 4 |
| 102 | 3 | 6 |
| 103 | 1 | 10 |
| 103 | 2 | 1 |
โบ
Output:
| candidate_id |
|--------------|
| 21 |
๐ก Note:
Only candidate 21 (Ruben) meets both criteria: has 6 years experience (โฅ2) and total interview score of 9+4+6=19 (>15). Candidate 11 has insufficient experience (1 year), and candidate 22 has sufficient experience but low score (10+1=11).
example_2.sql โ Edge Case: Exact Threshold
$
Input:
Candidates:
| candidate_id | name | years_of_exp | interview_id |
|--------------|------|--------------|---------------|
| 1 | John | 2 | 201 |
| 2 | Jane | 3 | 202 |
Rounds:
| interview_id | round_id | score |
|--------------|----------|-------|
| 201 | 1 | 15 |
| 202 | 1 | 16 |
โบ
Output:
| candidate_id |
|--------------|
| 2 |
๐ก Note:
Candidate 1 has exactly 15 points, but we need STRICTLY greater than 15. Only candidate 2 with 16 points qualifies.
example_3.sql โ Multiple Qualifying Candidates
$
Input:
Candidates:
| candidate_id | name | years_of_exp | interview_id |
|--------------|------|--------------|---------------|
| 10 | Alice | 5 | 301 |
| 20 | Bob | 3 | 302 |
| 30 | Carol | 8 | 303 |
Rounds:
| interview_id | round_id | score |
|--------------|----------|-------|
| 301 | 1 | 10 |
| 301 | 2 | 8 |
| 302 | 1 | 20 |
| 303 | 1 | 7 |
| 303 | 2 | 9 |
โบ
Output:
| candidate_id |
|--------------|
| 10 |
| 20 |
๐ก Note:
Alice (total: 18) and Bob (total: 20) both qualify with sufficient experience and scores >15. Carol has enough experience but only 16 total points, which does qualify her as well, so all three should be included.
Visualization
Tap to expand
Understanding the Visualization
1
Collect Applications
Gather all candidate profiles with their experience levels
2
Aggregate Scores
Sum up scores from all interview rounds for each candidate
3
Apply Filters
Check both experience requirement (โฅ2 years) and performance threshold (>15 points)
4
Select Winners
Accept candidates who meet both criteria
Key Takeaway
๐ฏ Key Insight: Using SQL JOIN with GROUP BY allows us to combine and aggregate data in a single efficient pass, eliminating the need for expensive correlated subqueries.
Time & Space Complexity
Time Complexity
O(n + m)
Single pass through candidates (n) and rounds (m) tables with efficient join
โ Linear Growth
Space Complexity
O(k)
Where k is the number of unique candidates for grouping
โ Linear Space
Constraints
- 1 โค candidate_id, interview_id โค 106
- 0 โค years_of_exp โค 50
- 1 โค round_id โค 10
- 0 โค score โค 100
- Each candidate has a unique interview_id
- Each interview has at least one round
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code