Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for [old] Merge Intervals by Moff
function mergeIntervals(intervals) {
let result = [];
for (let interval of intervals) {
for (let other of result.slice()) {
if (interval[0] < other[1] + 2) {
let i = result.indexOf(other);
result.splice(i, 1);
interval = [Math.min(interval[0], other[0]), Math.max(interval[1], other[1])];
}
}
result.push(interval);
}
return result;
}
July 31, 2017
Comments: