Maximum Team Size from Overlapping Availability

Quick Overview

Find the largest employee team with one member whose closed availability interval overlaps every other member, including interactions at shared endpoints.

Maximum Team Size from Overlapping Availability

Company: Salesforce

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

# Maximum Team Size from Overlapping Availability You are given two arrays, `startTime` and `endTime`, each of length `n`. Employee `i` is available throughout the closed interval `[startTime[i], endTime[i]]`. Two employees can interact when their intervals share at least one time point. A team is valid if at least one employee in that team can interact with every other member. Return the largest possible size of a valid team. Other pairs of team members need not overlap, and there need not be one time point shared by the entire team. ### Function `int maximumTeamSize(vector<int>& startTime, vector<int>& endTime)` ### Example 1 **Input:** `startTime = [2, 0, 6, 11], endTime = [8, 2, 6, 12]` **Output:** `3` **Explanation:** The employee with interval `[2, 8]` can interact with the employees available during `[0, 2]` and `[6, 6]`. These three employees form a valid team even though the latter two intervals do not overlap. The employee available during `[11, 12]` cannot join that team. ### Example 2 **Input:** `startTime = [5, 5, 8], endTime = [5, 7, 9]` **Output:** `2` **Explanation:** The first two employees can interact at time `5`, so they form a team of size `2`. The interval `[8, 9]` is disjoint from both of their intervals. ### Constraints - `1 <= n == startTime.length == endTime.length <= 100000` - `0 <= startTime[i] <= endTime[i] <= 1000000000` ### Clarifications - Touching at an endpoint counts as overlap. - A zero-length interval `[t, t]` is allowed. - The employee who overlaps everyone else is included in the team size. ### What a Strong Answer Covers - Applying the one-employee interaction requirement rather than requiring every pair to interact. - Handling equal endpoints, duplicate intervals and zero-length intervals correctly. - Supporting all `100000` employees without checking every pair separately.

Overview: Find the largest employee team with one member whose closed availability interval overlaps every other member, including interactions at shared endpoints.

Salesforce logo
Salesforce
Source window: 0–6 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Maximum Team Size from Overlapping Availability

You are given two arrays, startTime and endTime, each of length n. Employee i is available throughout the closed interval [startTime[i], endTime[i]].

Two employees can interact when their intervals share at least one time point. A team is valid if at least one employee in that team can interact with every other member.

Return the largest possible size of a valid team.

Other pairs of team members need not overlap, and there need not be one time point shared by the entire team.

Function

int maximumTeamSize(vector<int>& startTime, vector<int>& endTime)

Example 1

Input: startTime = [2, 0, 6, 11], endTime = [8, 2, 6, 12]

Output: 3

Explanation: The employee with interval [2, 8] can interact with the employees available during [0, 2] and [6, 6]. These three employees form a valid team even though the latter two intervals do not overlap. The employee available during [11, 12] cannot join that team.

Example 2

Input: startTime = [5, 5, 8], endTime = [5, 7, 9]

Output: 2

Explanation: The first two employees can interact at time 5, so they form a team of size 2. The interval [8, 9] is disjoint from both of their intervals.

Constraints

  • 1 <= n == startTime.length == endTime.length <= 100000
  • 0 <= startTime[i] <= endTime[i] <= 1000000000

Clarifications

  • Touching at an endpoint counts as overlap.
  • A zero-length interval [t, t] is allowed.
  • The employee who overlaps everyone else is included in the team size.

What a Strong Answer Covers Guidance

  • Applying the one-employee interaction requirement rather than requiring every pair to interact.
  • Handling equal endpoints, duplicate intervals and zero-length intervals correctly.
  • Supporting all 100000 employees without checking every pair separately.