PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

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.

  • medium
  • HubSpot
  • Coding & Algorithms
  • Software Engineer

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

  1. Model object-style prompts as arrays or operation streams when needed.
  2. Handle empty and boundary cases before the main logic.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Find a special person using knows(a,b) - HubSpot (easy)
  • Design and implement a bank account system - HubSpot (Medium)
  • Design file deduplication at scale - HubSpot (Medium)
  • Design a bank with scheduled payments and merges - HubSpot (Medium)
  • Implement a same-host web crawler - HubSpot (Medium)