Candidate Recruiter Management System with One-to-Many Assignment

Quick Overview

Design an in-memory system where each recruiter manages many candidates and each candidate has at most one recruiter, with add, assign, reassign, remove and lookup operations. It tests bidirectional mapping, keeping two indexes consistent through removals, and the cost of each operation.

Candidate Recruiter Management System with One-to-Many Assignment

Company: Goldman Sachs

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: easy

Interview Round: Other

Design a candidate/recruiter management system that models a one-to-many relationship: one recruiter manages many candidates, and each candidate is assigned to at most one recruiter at a time. The system must support adding recruiters and candidates, assigning candidates to recruiters, reassigning candidates between recruiters, removing entities, and querying which recruiter owns a candidate as well as listing all candidates owned by a recruiter. When a recruiter is removed, all of their candidates become unassigned but remain in the system. When a candidate is removed, they are detached from their recruiter (if any). Implement the following methods: - `addRecruiter(recruiterId: str) -> bool`: add a recruiter. Return True if added, False if the `recruiterId` already exists. - `addCandidate(candidateId: str) -> bool`: add a candidate (initially unassigned). Return True if added, False if the `candidateId` already exists. - `assign(candidateId: str, recruiterId: str) -> bool`: assign (or reassign) a candidate to a recruiter. Return True on success, False if either id does not exist. - `unassign(candidateId: str) -> bool`: detach a candidate from its current recruiter. Return True if the candidate was assigned, False otherwise. - `removeRecruiter(recruiterId: str) -> bool`: remove a recruiter; all of its candidates become unassigned. Return True if removed, False if not found. - `removeCandidate(candidateId: str) -> bool`: remove a candidate from the system. Return True if removed, False if not found. - `getRecruiter(candidateId: str) -> str`: return the `recruiterId` that owns the candidate, or an empty string if the candidate is unassigned or does not exist. - `getCandidates(recruiterId: str) -> List[str]`: return the sorted list of `candidateId`s owned by the recruiter, or an empty list if the recruiter does not exist or owns nobody. Example 1 (basic assignment): ```text Input: ["CandidateRecruiterSystem", "addRecruiter", "addCandidate", "addCandidate", "assign", "assign", "getRecruiter", "getCandidates"] [[], ["R1"], ["C1"], ["C2"], ["C1", "R1"], ["C2", "R1"], ["C1"], ["R1"]] Output: [null, true, true, true, true, true, "R1", ["C1", "C2"]] Explanation: sys = CandidateRecruiterSystem() # empty system sys.addRecruiter("R1") # -> True (R1 added) sys.addCandidate("C1") # -> True (C1 added, unassigned) sys.addCandidate("C2") # -> True (C2 added, unassigned) sys.assign("C1", "R1") # -> True (R1 owns {C1}) sys.assign("C2", "R1") # -> True (R1 owns {C1, C2}) sys.getRecruiter("C1") # -> "R1" sys.getCandidates("R1") # -> ["C1", "C2"] ``` Example 2 (reassignment and removal): ```text Input: ["CandidateRecruiterSystem", "addRecruiter", "addRecruiter", "addCandidate", "addCandidate", "assign", "assign", "assign", "getCandidates", "removeRecruiter", "getRecruiter", "unassign", "removeCandidate", "getCandidates"] [[], ["R1"], ["R2"], ["C1"], ["C2"], ["C1", "R1"], ["C2", "R1"], ["C1", "R2"], ["R1"], ["R2"], ["C1"], ["C1"], ["C2"], ["R1"]] Output: [null, true, true, true, true, true, true, true, ["C2"], true, "", false, true, []] Explanation: sys = CandidateRecruiterSystem() sys.addRecruiter("R1") # -> True sys.addRecruiter("R2") # -> True sys.addCandidate("C1") # -> True sys.addCandidate("C2") # -> True sys.assign("C1", "R1") # -> True (R1 owns {C1}) sys.assign("C2", "R1") # -> True (R1 owns {C1, C2}) sys.assign("C1", "R2") # -> True (reassigned: R1 owns {C2}, R2 owns {C1}) sys.getCandidates("R1") # -> ["C2"] sys.removeRecruiter("R2") # -> True (C1 stays in the system, unassigned) sys.getRecruiter("C1") # -> "" (unassigned) sys.unassign("C1") # -> False (C1 was not assigned) sys.removeCandidate("C2") # -> True (C2 detached from R1 and removed) sys.getCandidates("R1") # -> [] ``` ```hint Unassigned is still present Removing a recruiter must leave its candidates in the system. Make sure your model can tell an unassigned candidate apart from one that was never added, and find every operation where both directions of the relationship have to change together. ``` ### Constraints & Assumptions - `1 <= number of recruiters <= 10^4` - `1 <= number of candidates <= 10^4` - `recruiterId` and `candidateId` are non-empty strings of length up to `50`. - A candidate can be assigned to at most one recruiter at any time. - All ids are unique within their entity type. ### Clarifying Questions to Ask - Can a recruiter and a candidate share the same id string, given that ids are only unique within their own type? - Should assigning a candidate to the recruiter that already owns it return True and leave everything unchanged? - Does "sorted" mean plain string order (where "C10" comes before "C2") or a natural numeric order? - Will the system be called from several threads, or is a single-threaded design enough? ### What a Strong Answer Covers - The data structures for both lookup directions and the invariant that keeps them consistent. - How an unassigned candidate is represented so it survives the removal of its recruiter. - Correct return values for every method, including reassignment, assigning to the current owner, and calls with unknown ids. - Time and space complexity of each operation, including `removeRecruiter` and the sorted listing. ### Follow-up Questions - `getCandidates` is called far more often than `assign`. How would you avoid sorting on every call? - How would you make the system safe for concurrent use, and which operations must be atomic across both structures? - How would you keep an assignment history so you can answer which recruiter owned a candidate on a given date? - How would you add a limit on how many candidates one recruiter can own?

Overview: Design an in-memory system where each recruiter manages many candidates and each candidate has at most one recruiter, with add, assign, reassign, remove and lookup operations. It tests bidirectional mapping, keeping two indexes consistent through removals, and the cost of each operation.

Goldman Sachs logo
Goldman Sachs
Nov 24, 2026
easySoftware EngineerOtherSoftware Engineering Fundamentals
0
0

Design a candidate/recruiter management system that models a one-to-many relationship: one recruiter manages many candidates, and each candidate is assigned to at most one recruiter at a time.

The system must support adding recruiters and candidates, assigning candidates to recruiters, reassigning candidates between recruiters, removing entities, and querying which recruiter owns a candidate as well as listing all candidates owned by a recruiter.

When a recruiter is removed, all of their candidates become unassigned but remain in the system. When a candidate is removed, they are detached from their recruiter (if any).

Implement the following methods:

  • addRecruiter(recruiterId: str) -> bool : add a recruiter. Return True if added, False if the recruiterId already exists.
  • addCandidate(candidateId: str) -> bool : add a candidate (initially unassigned). Return True if added, False if the candidateId already exists.
  • assign(candidateId: str, recruiterId: str) -> bool : assign (or reassign) a candidate to a recruiter. Return True on success, False if either id does not exist.
  • unassign(candidateId: str) -> bool : detach a candidate from its current recruiter. Return True if the candidate was assigned, False otherwise.
  • removeRecruiter(recruiterId: str) -> bool : remove a recruiter; all of its candidates become unassigned. Return True if removed, False if not found.
  • removeCandidate(candidateId: str) -> bool : remove a candidate from the system. Return True if removed, False if not found.
  • getRecruiter(candidateId: str) -> str : return the recruiterId that owns the candidate, or an empty string if the candidate is unassigned or does not exist.
  • getCandidates(recruiterId: str) -> List[str] : return the sorted list of candidateId s owned by the recruiter, or an empty list if the recruiter does not exist or owns nobody.

Example 1 (basic assignment):

Input:
["CandidateRecruiterSystem", "addRecruiter", "addCandidate", "addCandidate", "assign",     "assign",     "getRecruiter", "getCandidates"]
[[],                         ["R1"],         ["C1"],         ["C2"],         ["C1", "R1"], ["C2", "R1"], ["C1"],         ["R1"]]

Output: [null, true, true, true, true, true, "R1", ["C1", "C2"]]

Explanation:
sys = CandidateRecruiterSystem()       # empty system

sys.addRecruiter("R1")                 # -> True   (R1 added)
sys.addCandidate("C1")                 # -> True   (C1 added, unassigned)
sys.addCandidate("C2")                 # -> True   (C2 added, unassigned)
sys.assign("C1", "R1")                 # -> True   (R1 owns {C1})
sys.assign("C2", "R1")                 # -> True   (R1 owns {C1, C2})
sys.getRecruiter("C1")                 # -> "R1"
sys.getCandidates("R1")                # -> ["C1", "C2"]

Example 2 (reassignment and removal):

Input:
["CandidateRecruiterSystem", "addRecruiter", "addRecruiter", "addCandidate", "addCandidate", "assign", "assign", "assign", "getCandidates", "removeRecruiter", "getRecruiter", "unassign", "removeCandidate", "getCandidates"]
[[], ["R1"], ["R2"], ["C1"], ["C2"], ["C1", "R1"], ["C2", "R1"], ["C1", "R2"], ["R1"], ["R2"], ["C1"], ["C1"], ["C2"], ["R1"]]

Output: [null, true, true, true, true, true, true, true, ["C2"], true, "", false, true, []]

Explanation:
sys = CandidateRecruiterSystem()

sys.addRecruiter("R1")                 # -> True
sys.addRecruiter("R2")                 # -> True
sys.addCandidate("C1")                 # -> True
sys.addCandidate("C2")                 # -> True
sys.assign("C1", "R1")                 # -> True   (R1 owns {C1})
sys.assign("C2", "R1")                 # -> True   (R1 owns {C1, C2})
sys.assign("C1", "R2")                 # -> True   (reassigned: R1 owns {C2}, R2 owns {C1})
sys.getCandidates("R1")                # -> ["C2"]
sys.removeRecruiter("R2")              # -> True   (C1 stays in the system, unassigned)
sys.getRecruiter("C1")                 # -> ""     (unassigned)
sys.unassign("C1")                     # -> False  (C1 was not assigned)
sys.removeCandidate("C2")              # -> True   (C2 detached from R1 and removed)
sys.getCandidates("R1")                # -> []

Constraints & Assumptions

  • 1 <= number of recruiters <= 10^4
  • 1 <= number of candidates <= 10^4
  • recruiterId and candidateId are non-empty strings of length up to 50 .
  • A candidate can be assigned to at most one recruiter at any time.
  • All ids are unique within their entity type.

Clarifying Questions to Ask Guidance

  • Can a recruiter and a candidate share the same id string, given that ids are only unique within their own type?
  • Should assigning a candidate to the recruiter that already owns it return True and leave everything unchanged?
  • Does "sorted" mean plain string order (where "C10" comes before "C2") or a natural numeric order?
  • Will the system be called from several threads, or is a single-threaded design enough?

What a Strong Answer Covers Guidance

  • The data structures for both lookup directions and the invariant that keeps them consistent.
  • How an unassigned candidate is represented so it survives the removal of its recruiter.
  • Correct return values for every method, including reassignment, assigning to the current owner, and calls with unknown ids.
  • Time and space complexity of each operation, including removeRecruiter and the sorted listing.

Follow-up Questions Guidance

  • getCandidates is called far more often than assign . How would you avoid sorting on every call?
  • How would you make the system safe for concurrent use, and which operations must be atomic across both structures?
  • How would you keep an assignment history so you can answer which recruiter owned a candidate on a given date?
  • How would you add a limit on how many candidates one recruiter can own?