• + 0 comments

    My typescript solution:

    let maxCount = 0;
        let lastTwo = [[0,0],[0,0]];
        intervals.sort((a,b) => a[1]-b[1]);
        intervals.forEach((interval) => {
            if(interval[0] > lastTwo[1][1]) {
                maxCount++;
                lastTwo[1] = interval;
            } else if (interval[0] > lastTwo[0][1]) {
                maxCount++;
                lastTwo[0] = interval
                lastTwo.sort((a,b) => a[1]-b[1])
            }
        })
        return maxCount;