ІМ
Size: a a a
ЕМ
IS
D
D
D
Q
n log n
const maxIntersection = (list) => {
const allTimesValues = list.reduce((acc, { from, to }) => {
acc.push([from, "start"]);
acc.push([to, "end"]);
return acc;
}, []);
const sortedTimes = allTimesValues.sort((a, b) => a[0] - b[0]);
let max, numberOfCalls = 0;
sortedTimes.forEach((range) => {
if (range[1] === "start") numberOfCalls += 1;
if (range[1] === "end") numberOfCalls -= 1;
max = Math.max(numberOfCalls, max);
});
return max;
};
RR
BB
IS
BB
IS
Q
j
IS
IS
IS
Q
IS
j
function solve( callList ){
var z = callList.map( c=> Array.from(Array(c.to-c.from), (_,k)=>c.from+k+1))
return 'Максимальное число занятых телефонных линий ' + Math.max(...Object.values([].concat(...z).reduce((x,y)=>(x[y]=-~x[y],x),{})))
}