You're tasked with finding the minimum number of integers that can cover multiple intervals with a special constraint: each interval must contain at least two of your chosen integers.
Given a 2D array intervals where intervals[i] = [start_i, end_i] represents all integers from start_i to end_i inclusively, you need to create a containing set - an array of numbers where each interval has at least two integers from your set.
Example: If intervals = [[1,3], [3,7], [8,9]], then [1,2,4,7,8,9] and [2,3,4,8,9] are both valid containing sets, but [2,3,4,8,9] is smaller with only 5 elements.
Your goal is to return the minimum possible size of such a containing set. This is a classic optimization problem that tests your understanding of greedy algorithms and interval scheduling.
Input & Output
Constraints
- 1 โค intervals.length โค 3000
- intervals[i].length == 2
- 0 โค starti < endi โค 1000
- Each interval must contain at least 2 integers from the result set