Given a set of intervals [x,y] where 0 <= x,y <= 2000
how to find minimum number of points which can cover(i.e. Every interval should contain at least one point in resultant set of points) all intervals?
example:
Given Set of intervals:
[2,5]
[3,7]
[7,10]
then answer should be 2 (minimum number of points required to cover all intervals) as points x=3,x=7
is one solution.
You can use a greedy algorithm:
Sort all intervals by their end points(in increasing order).
Iterate over a sorted array of intervals. When an interval is over, there are two options:
The resulting set generated by this algorithm is optimal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With