This question evaluates the ability to enforce cardinality constraints and manage state across related entities, testing competencies in data consistency, edge-case handling, and algorithmic efficiency when tracking assignments.
You are building a simple HR assignment validator for a platform with companies, employees, and job roles.
When the system receives a request to assign an employee to a role in a company, it must enforce the following rules:
If a request violates any rule, the system must return invalid and also provide a reason. Otherwise, it should apply the assignment and return valid.
add
requests, each of the form:
employee_id
,
company_id
,
role_name
For each add request, output either:
valid
(and the assignment is applied), or
invalid: <reason>
where
<reason>
clearly states which rule was violated.
valid
(no-op), unless you choose to define it as an error—state your assumption.
10^5
total assignments and requests.
Given existing assignments where role SWE at company C1 already has 5 employees, adding another SWE to C1 should return:
invalid: role capacity exceeded (max 5 per role per company)