All problems
0841MediumArraySortingGreedyPrefix Sum

Largest Crew on Shift Together

Tracked in this browser only
Write code

Trains the technique from

LeetCode 3893Maximum Team Size with Overlapping Intervals

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

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