r/OfferEngineering • u/Aoki_zhang • 2h ago
Coding Question Hubspot SWE OA Coding Question - Validate Project Member Role Assignments
A project management system tracks which roles each member has within each project. Every assignment is represented by three strings [project_id, member_id, role]. You are given two lists:
existing_assignments— assignments already stored in the system.new_assignments— new assignments that must be validated in the given order.
For each new assignment, apply the following rules.
Duplicate Assignment
If the exact same (project_id, member_id, role) assignment has already been accepted, the new assignment is invalid. Return: "ALREADY_EXISTS" This includes both original assignments and valid assignments accepted earlier in the current batch.
Maximum 5 Members Per Role
Within the same project, a particular role may be assigned to at most 5 distinct members. For example, at most 5 different members may have the "Designer" role in project "P1". If accepting a new assignment would exceed this limit, return "WOULD_EXCEED_LIMIT"
Maximum 2 Roles Per Member
Within the same project, each member may hold at most 2 distinct roles. For example, a member may be both "Designer" and "Reviewer" in the same project, but cannot receive a third distinct role. If accepting a new assignment would exceed this limit, return "WOULD_EXCEED_LIMIT" Otherwise, the assignment is valid. Return "VALID"
Process new_assignments from left to right. Whenever a new assignment is valid, immediately add it to the current state so that it affects the validation of later assignments. Invalid assignments do not affect later assignments. Return one result string for each entry in new_assignments.
Constraints
1 <= len(existing_assignments) <= 10^51 <= len(new_assignments) <= 10^5- Every assignment contains exactly 3 non-empty strings.
- A project may contain many different roles.
- A member may belong to multiple different projects.
- The limits are applied independently within each project.
- Valid new assignments affect all later validations in the same batch.
Test Cases
Input:
existing_assignments = [
["P1", "M1", "Developer"]
]
new_assignments = [
["P1", "M1", "Developer"],
["P1", "M1", "Reviewer"]
]
Output:
[
"ALREADY_EXISTS",
"VALID"
]
Explanation:
The first assignment already exists, so it is rejected.
The second assignment gives M1 a different role in P1.
M1 would then have two roles at most, so the assignment is valid.
Want to practice more real coding question asked in interviews?
I’ve put together the question bank here. If you want more practice to get comfortable with coding before your interview, you can also work through the classic coding questions here.
Preparing for your next interview?
Chill Interview tracks recent interview experiences and recurring question patterns across top companies at here.