Maximum Team Size with Overlapping Intervals
Real-world version: Largest Crew on Shift TogetherThe 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.
def largest_overlap_crew(startTime: list[int], endTime: list[int]) -> int:public int largestOverlapCrew(int[] startTime, int[] endTime)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 13 test cases: 13 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Longest Subsequence With Limited SumReal-world version: Parcels Within Each AllowanceEasy
- Meeting Rooms IIReal-world version: Peak Charging Bay DemandMedium
- Frequency of the Most Frequent ElementReal-world version: Plates at One ThicknessMedium
- Maximum Coins From K Consecutive BagsReal-world version: Richest Run of Consecutive BinsMedium