InterviewDB Question

Candidate Connection - Match Job Candidates to Positions by Skills

Question Details

Problem

You have a list of candidates {id, skills: Set[str]} and a list of positions {id, required_skills: Set[str], preferred_skills: Set[str]}. Find the best candidate for each position. Score:

  • +2 per required skill matched.
  • +1 per preferred skill matched.
  • A candidate is eligible only if they match ALL required skills.

Return the top match per position (highest score; break ties by candidate ID ascending).

Return null if no eligible candidate exists.

python
def match_candidates(
    candidates: List[dict],
    positions: List[dict]
) -> dict:  # {position_id: candidate_id | None}
    ...

Example:

candidates = [{"id":"c1","skills":{"python","sql","ml"}},
              {"id":"c2","skills":{"python","sql"}}]
positions  = [{"id":"p1","required_skills":{"python","sql"},
                          "preferred_skills":{"ml"}}]
match_candidates -> {"p1": "c1"}  # c1 scores 2+2+1=5, c2 scores 2+2=4

Follow-ups

  1. How would you turn this into a bipartite maximum matching problem?
  2. Extend to return the top 3 candidates per position.
  3. How do you handle partial skill matches (e.g., "Python 3" matches "Python")?
  4. If there are 100K candidates and 10K positions, how do you avoid O(n*m) computation?

Full Details

Problem

You have a list of candidates {id, skills: Set[str]} and a list of positions {id, required_skills: Set[str], preferred_skills: Set[str]}. Find the best candidate for each position. Score:

  • +2 per required skill matched.
  • +1 per preferred skill matched.
  • A candidate is eligible only if they match ALL required skills.

Return the top match per position (highest score; break ties by candidate ID ascending).

Return null if no eligible candidate exists.

python
def match_candidates(
    candidates: List[dict],
    positions: List[dict]
) -> dict:  # {position_id: candidate_id | None}
    ...

Example:

candidates = [{"id":"c1","skills":{"python","sql","ml"}},
              {"id":"c2","skills":{"python","sql"}}]
positions  = [{"id":"p1","required_skills":{"python","sql"},
                          "preferred_skills":{"ml"}}]
match_candidates -> {"p1": "c1"}  # c1 scores 2+2+1=5, c2 scores 2+2=4

Follow-ups

  1. How would you turn this into a bipartite maximum matching problem?
  2. Extend to return the top 3 candidates per position.
  3. How do you handle partial skill matches (e.g., "Python 3" matches "Python")?
  4. If there are 100K candidates and 10K positions, how do you avoid O(n*m) computation?
Free preview. Unlock all questions →

Topics

Coding Onsite Phone