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 ID
  • Rounds - 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
Interview Candidate Evaluation Process๐Ÿ“‹ CandidatesA: 3yrB: 1yrC: 5yr๐ŸŽฏ Score RoundsR1R2R3Sum scores per candidate๐Ÿ” Filter LogicExperience โ‰ฅ 2 yearsTotal Score > 15โœ… ResultsA โœ“C โœ“AcceptedSQL JOIN + GROUP BY StrategyJOIN tables โ†’ GROUP BY candidate โ†’ SUM scores โ†’ HAVING total > 15
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

n
2n
โœ“ Linear Growth
Space Complexity
O(k)

Where k is the number of unique candidates for grouping

n
2n
โœ“ 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
Asked in
Microsoft 35 Amazon 28 Google 22 Meta 18
24.5K Views
Medium Frequency
~12 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