FastPrepLargest Team Where Every Pair Overlaps

Largest Team Where Every Pair Overlaps

Walmart logoWalmart● MediumFULLTIMEOA

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[]) → int

Examples

Example 1

startTime = [1,2,4,7]endTime = [3,5,6,8]return = 2

The working hours are [1, 3], [2, 5], [4, 6], and [7, 8].

  • Employees 0 and 1 are both working from time 2 to 3, so they can be a team of 2.
  • Employees 1 and 2 are both working from time 4 to 5, so they can also be a team of 2.
  • Employees 0 and 2 never work at the same time, and employee 3 overlaps nobody, so no team of 3 works.

Example 2

startTime = [1,3,3]endTime = [3,5,3]return = 3

The 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 = 2

Employee 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^4
  • endTime.length == startTime.length
  • 0 <= startTime[i] <= endTime[i] <= 10^9

More Walmart problems

See Walmart hiring insights
Saved
public int maxTeamSize(int[] startTime, int[] endTime) {
    // Write your solution here.
}
Checking account…