Problem
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:
-
Role capacity per company:
In a given company,
each role
can be held by
at most 5 employees
at the same time.
-
Max roles per employee per company:
An employee can hold
at most 2 roles in the same company
at the same time.
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.
Input
-
An initial set of existing assignments.
-
A sequence of
add
requests, each of the form:
-
employee_id
,
company_id
,
role_name
Output
For each add request, output either:
-
valid
(and the assignment is applied), or
-
invalid: <reason>
where
<reason>
clearly states which rule was violated.
Notes / Clarifications
-
If an employee is already assigned to the same role in the same company, treat it as
valid
(no-op), unless you choose to define it as an error—state your assumption.
-
If both rules would be violated, you may return either a single reason or multiple reasons, but be consistent.
Constraints (you may assume)
-
Up to
10^5
total assignments and requests.
-
IDs/role names are strings.
Example (illustrative)
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)