Maximum Team Size with an Overlapping Hub
Company: Microsoft
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Online Assessment
There are `n` employees. Employee `i` works during the closed interval `[startTime[i], endTime[i]]`. Two employees can interact if their working intervals overlap. Intervals that share an endpoint count as overlapping.
A team is valid if at least one member can interact with every other member of that team. Other pairs of team members do not need to interact, and the entire team does not need to share one common time.
Implement `getMaximumTeamSize(startTime, endTime)` and return the largest possible valid team size.
### Input and Output
- `startTime` and `endTime` are integer arrays of the same length `n`.
- Return an integer representing the maximum number of employees in a valid team.
- Employees are distinct even when their intervals are identical.
### Constraints & Assumptions
- `1 <= n <= 2 * 10^5`
- `1 <= startTime[i] <= endTime[i] <= 10^9`
- Both endpoints are included. A zero-length interval is valid.
- The employee who overlaps everyone else is part of the team and counts toward its size.
### Examples
**Example 1**
```text
startTime = [1, 6, 4, 3, 1]
endTime = [2, 7, 5, 8, 2]
Output: 3
```
Employee `3`, with interval `[3, 8]`, overlaps employees `1` and `2`. Thus employees `[1, 2, 3]` form a valid team. Employees `1` and `2` do not overlap each other, but that is allowed. No employee can serve as the hub of a larger team.
**Example 2**
```text
startTime = [2, 5, 6, 8]
endTime = [5, 6, 10, 9]
Output: 3
```
Employee `1`, with interval `[5, 6]`, overlaps employee `0` at time `5` and employee `2` at time `6`. The team `[0, 1, 2]` is valid, even though those three intervals have no common intersection.
**Example 3**
```text
startTime = [1, 2, 8, 8, 10]
endTime = [4, 8, 12, 9, 11]
Output: 4
```
Employee `1`, with interval `[2, 8]`, overlaps employees `0`, `2`, and `3`. These four employees form a valid team. No single employee overlaps all five intervals.
### Clarifying Questions to Ask
- Does a team require one member who overlaps everyone, or must every pair overlap? Here, only the first condition is required.
- Are endpoint-only intersections valid? Yes, the intervals are closed.
- Should equal intervals be deduplicated? No, they belong to distinct employees.
```hint
Fix one employee as the hub. Which other intervals are definitely unable to join that employee's team?
```
### What a Strong Answer Covers
The solution should count all intervals intersecting each possible hub, including the hub itself, and maximize that count. It should handle inclusive endpoints and repeated intervals, avoid confusing this problem with maximum simultaneous attendance, and use an approach suitable for two hundred thousand employees.
### Follow-up Questions
- How would you return the members of one optimal team after finding its hub?
- Which comparison operators would change if touching endpoints did not count as overlap?
- How would the task change if every pair of team members had to overlap?
Overview: Find the largest employee team with one member whose working interval overlaps every teammate's interval. Preserve inclusive endpoints and distinguish the hub condition from a shared meeting time while deriving an O(n log n) counting solution.
There are n employees. Employee i works during the closed interval [startTime[i], endTime[i]]. Two employees can interact when their intervals overlap, including when they share only an endpoint. A team is valid if at least one member overlaps every other member of the team. The other pairs need not overlap, and the team need not share a common time. Implement getMaximumTeamSize(startTime, endTime) and return the maximum possible valid team size. Employees are distinct even if their intervals are identical.
Example 1: startTime = [1, 6, 4, 3, 1], endTime = [2, 7, 5, 8, 2], output 3. The interval [3, 8] can serve as a hub for [6, 7] and [4, 5].
Example 2: startTime = [2, 5, 6, 8], endTime = [5, 6, 10, 9], output 3. The interval [5, 6] touches one member at 5 and another at 6.
Example 3: startTime = [1, 2, 8, 8, 10], endTime = [4, 8, 12, 9, 11], output 4.
Constraints
- 1 <= n <= 200000.
- startTime and endTime are integer arrays of the same length n.
- 1 <= startTime[i] <= endTime[i] <= 1000000000.
- Intervals include both endpoints, and zero-length intervals are valid.
- The overlapping hub counts as one team member; identical intervals still represent distinct employees.
Examples
Input: ([1], [1])
Expected Output: 1
Explanation: The sole zero-length interval is the hub and whole team.
Input: ([1, 6, 4, 3, 1], [2, 7, 5, 8, 2])
Expected Output: 3
Explanation: The [3,8] interval overlaps [6,7] and [4,5], but no hub reaches four.
Hints
- A team may remain valid even if two non-hub members never meet.
- An intersection at exactly one endpoint counts.