Given the interval list
[[0,30],[1,5],[6,10],[11,15],[16,20], [21,25]]
Where the first element for each list is the start time, and the second element is the end time.
We see that 0 - 30 overlaps with all other 5 intervals, and all the other interval only overlaps once with another interval, so the maximum number of overlapping is 5.
Im seeing alot of answers online about finding the minimum number of platform or room needed for conference or train from
http://www.geeksforgeeks.org/minimum-number-platforms-required-railwaybus-station/
http://www.zrzahid.com/maximum-number-of-overlapping-intervals/
But I don't see how those algo applies to this question, as I have tried the algo and they will return 2 for the number of platform and room needed for this example input list, as they will try to find the maximum number of overlap at a particular time, but I want to know the maximum number of overlap that can happen during the entire time interval.
Below is my brute force approach, and it works, but how can I minimize the runtime to O(nlogn) if possible?
function maxNumConflict(intervals) {
max = 0;
for (var i = 0; i < intervals.length; i++) {
tempMax = 0;
for (var j = i + 1; j < intervals.length; j++) {
if (overlap(intervals[i], intervals[j])) {
tempMax++;
}
}
max = Math.max(tempMax, max);
}
return max;
}
function overlap(i1, i2) {
return ((i1[0] >= i2[0] && i1[0] < i2[1])
|| (i2[0] >= i1[0] && i2[0] < i1[1]));
}
console.log(maxNumConflict(([[0,30],[1,5],[6,10],[11,15],[16,20], [21,25]])));