Arrays left and right describe intervals [left[i], right[i]]. Return the largest number of intervals you can select such that no two selected intervals overlap.
Function Signature
def maximum_disjoint_intervals(left: list[int], right: list[int]) -> int:
Rules
-
For this practice version, intervals are closed: sharing an endpoint counts as overlap.
-
Each input position describes one interval. Duplicate intervals are separate choices but cannot both be selected.
-
Return the maximum count only. Do not return the selected intervals.
Constraints
These bounds and endpoint semantics define this practice version.
-
0 <= len(left) == len(right) <= 100000
.
-
-1000000000 <= left[i] <= right[i] <= 1000000000
.
-
Endpoints fit in signed 32-bit integers. Zero-length intervals are permitted.
Examples
Input: left = [3, 5, 8], right = [4, 6, 9]
Output: 3
The intervals [3,4], [5,6], and [8,9] are all disjoint.
Input: left = [1, 2, 4], right = [3, 2, 5]
Output: 2
Choose [2,2] and [4,5].
Input: left = [1, 2], right = [2, 3]
Output: 1
These closed intervals share endpoint 2.