I have many intervals of positive integer numbers that each of them has a score. I want to find a set of intervals that do not have any overlapping. I have these conditions for selecting overlapped intervals:
1.if two interval overlap then select an interval with high score.
2.if both have same score, select the first interval.
for example if we have these intervals(order is important):
[0,3],[5,9],[1,4],[12,15],[17,20],[13,16],[16,16],[22,24]
score={1,5,0,12,17,13,20,22}
The result intervals are:
[0,3],[5,9],[16,16],[22,24]
I have to define intervals as follows:
int[] intervalStart={0,5,1,12,17,13,16,22};
int[] intervalEnd={3,9,4,15,20,16,16,24};
int[] scores={1,5,0,12,17,13,20,22};
and excepted result is an array that consist of selected interval indexes:
int[] result={0,1,6,7};
How to doing it and find this set?