I have n
integers and m
ranges (think [a, b]
) of numbers such that n <= m
. An integer and a range may be matched if the integer is in the range, i.e., a <= integer <= b
. A range may only be matched with one integer and vice versa.
Here is an example:
Ranges: [0, 5], [3, 6], [9, 21]
Integers: 1, 5
The maximum valid matching is to match 1
to the first range and 5
to the second range.
I want to find a greedy algorithm that maximizes the number of integers matched. My initial thought is to greedily choose the shortest range and match the number which is closest to the shortest range's start point (so the a
in a range [a, b]
). Howveer, I'm not sure this is right.