00:01
So to solve this problem using a greedy algorithm, you can follow these steps.
00:06
Greedy algorithm.
00:15
So we need to sort the intervals in set 1 based on their right endpoints in ascending order.
00:24
We need to initialize an empty subset s to store the selected intervals.
00:30
We need to iterate through the sorted intervals.
00:33
So for each interval, if its left endpoint covers any number in set n, that is not already covered, add it to s and update the set of covered numbers.
00:43
And then 4, we return to the subset.
00:46
So in this case, we're returning to subset s as the smallest subsets of intervals that covers all numbers in set n.
00:55
So do note that the greedy strategy here is to always select the interval with the smallest right endpoint that covers an uncovered number from set n.
01:10
So by selecting intervals this way, we aim to maximize the coverage of numbers with the smallest possible intervals.
01:18
So we need to sort intervals based on right endpoints.
01:39
We need to initialize s as an empty set and the set of covered numbers as an empty set.
02:11
We need to iterate through sorted intervals and we need to return the subset s.
02:37
And remember for point 3, if the left endpoint of the current interval covers an uncovered number set from set n, add it to s and update the set of covered numbers...