Validate hiring request under role constraints
Company: HubSpot
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
## 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:
1. **Role capacity per company:** In a given company, **each role** can be held by **at most 5 employees** at the same time.
2. **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)`
Quick Answer: 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.
Apply assignment add requests. Same employee/company/role is a valid no-op. Return result strings for each request.
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: ([('e1','c1','SWE'),('e2','c1','SWE'),('e3','c1','SWE'),('e4','c1','SWE'),('e5','c1','SWE')], [('e6','c1','SWE')])
Expected Output: ['invalid: role capacity exceeded (max 5 per role per company)']
Explanation: Role at capacity.
Input: ([('e1','c1','A'),('e1','c1','B')], [('e1','c1','C'),('e1','c1','A')])
Expected Output: ['invalid: employee role limit exceeded (max 2 per employee per company)', 'valid']
Explanation: Employee limit and duplicate no-op.
Input: ([], [('e1','c1','SWE')])
Expected Output: ['valid']
Explanation: Valid new assignment.
Hints
- Model object-style prompts as arrays or operation streams when needed.
- Handle empty and boundary cases before the main logic.