Largest Team Where Every Pair Overlaps
Problem statement
A company has n employees. Employee i works from time startTime[i] to time endTime[i], and both ends are part of the working hours.
Two employees can interact when their working hours overlap, which means there is at least one moment when both of them are working. Working hours that only touch still overlap. For example, [1, 3] and [3, 5] overlap at time 3.
A team is valid when every employee in the team can interact with every other employee in the team. A team of one employee is always valid.
Return the size of the largest valid team.
Function
maxTeamSize(startTime: int[], endTime: int[]) → intExamples
Example 1
startTime = [1,2,4,7]endTime = [3,5,6,8]return = 2The working hours are [1, 3], [2, 5], [4, 6], and [7, 8].
- Employees
0and1are both working from time2to3, so they can be a team of 2. - Employees
1and2are both working from time4to5, so they can also be a team of 2. - Employees
0and2never work at the same time, and employee3overlaps nobody, so no team of 3 works.
Example 2
startTime = [1,3,3]endTime = [3,5,3]return = 3The working hours are [1, 3], [3, 5], and [3, 3]. All three include time 3.
Working hours that only touch still overlap, so every pair can interact and the whole group of 3 is a valid team.
Example 3
startTime = [0,1,4,7]endTime = [10,2,5,8]return = 2Employee 0 works [0, 10] and overlaps everyone else.
Employees 1, 2, and 3 work [1, 2], [4, 5], and [7, 8], which never overlap each other. A team with two of them is not valid, so the largest team is employee 0 with one other employee, which has size 2.
Constraints
1 <= startTime.length <= 10^4endTime.length == startTime.length0 <= startTime[i] <= endTime[i] <= 10^9