Given a list of time ranges, I need to find the maximum number of overlaps.
Following is a dataset showing a 10 minute interval of calls, from which I am trying to f
In my opinion greedy algorithm will do the needful. The problem is similar to find out the number of platforms required for given trains timetable. So the number of overlaps will be the number of platforms required.
callStart times are sorted. Start putting each call in an array(a platform). So for call i and (i + 1)
, if callEnd[i] > callStart[i+1]
then they can not go in the same array (or platform) put as many calls in the first array as possible. Then repeat the process with rest ones till all calls are exhausted. In the end, number of arrays are maximum number of overlaps. And the complexity will be O(n)
.
The following page has examples of solving this problem in many languages: http://rosettacode.org/wiki/Max_Licenses_In_Use
Following must work:
numberOfCalls
to 0 (count variable)Run through your time values and:
Complexity: O(n log(n)) for sorting, O(n) to run through all records