function findFreeMeetingSlots(slots) {
const busy = slots
.flat()
.sort((a, b) => a[0] - b[0])
.reduce((acc, [start, end]) => {
const last = acc[acc.length - 1];
 
if (!last || start > last[1]) {
acc.push([start, end]);
} else {
last[1] = Math.max(last[1], end);
}
 
return acc;
}, []);
 
let start = 0;
 
return busy
.reduce((free, [busyStart, busyEnd]) => {
if (start < busyStart) {
free.push([start, busyStart]);
}
 
start = Math.max(start, busyEnd);
 
return free;
}, [])
.concat(start < 24 ? [[start, 24]] : []);
}
 
console.log(findFreeMeetingSlots([
[[16, 18], [11, 12], [14, 15]],
[[15, 17]],
[[10, 13]]
]));
 
// Ожидаемый результат:
// [[0, 10], [13, 14], [18, 24]]
 
 
 
 
 
 
 
 
 
Code will run automatically after changes.
Code runs in an isolated environment.