Show problems as
Classic problem #3893MediumArraySortingGreedyPrefix Sum

Maximum Team Size with Overlapping Intervals

Real-world version: Largest Crew on Shift Together
Tracked in this browser only
Read Maximum Team Size with Overlapping Intervals on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A depot logs one shift per worker. Worker i clocks on at minute startTime[i] and clocks off at minute endTime[i], and is counted as present at both of those minutes and at every minute between them.

A group of workers can hold a briefing when there is some minute at which every worker in the group is present. Return the size of the largest such group.

Examples

Example 1

Input
startTime = [6, 8, 9, 20], endTime = [10, 12, 11, 25]
Output
3

At minute 9 the workers in slots 0, 1 and 2 are all present, since 9 lies inside each of their shifts, so those three can brief together. The worker in slot 3 is not present at minute 9.

Example 2

Input
startTime = [0, 4], endTime = [4, 8]
Output
2

The first worker is present at minute 4 because a worker counts as present at the minute they clock off, and the second is present at minute 4 because that is when they clock on.

Example 3

Input
startTime = [0, 5, 10], endTime = [4, 9, 14]
Output
1

No minute is covered by two of these shifts, so only a single worker can be present at once.

Constraints

  • 1 <= startTime.length <= 10^5
  • startTime.length == endTime.length
  • 0 <= startTime[i] <= 10^9
  • 0 <= endTime[i] <= 10^9
  • startTime[i] <= endTime[i] for every worker

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def largest_overlap_crew(startTime: list[int], endTime: list[int]) -> int:
Java
public int largestOverlapCrew(int[] startTime, int[] endTime)