Last active
October 4, 2020 16:50
-
-
Save manzaloros/32dd20e5e6899a5f55c6893ae9bf7b67 to your computer and use it in GitHub Desktop.
removeCoveredIntervals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const removeCoveredIntervals = (intervals) => { | |
let coveredIntervalsCount = 0; | |
const compareSet = new Set(); | |
for (let i = 0; i < intervals.length; i += 1) { | |
const current = intervals[i]; | |
for (let j = 0; j < intervals.length; j += 1) { | |
if (j === i || compareSet.has((intervals[j].toString()))) { | |
continue; | |
} | |
const compare = intervals[j]; | |
if (current[0] <= compare[0] && current[1] >= compare[1]) { | |
compareSet.add(compare.toString()); | |
coveredIntervalsCount += 1; | |
} | |
} | |
} | |
return intervals.length - coveredIntervalsCount; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment