Created
November 3, 2021 19:54
-
-
Save olabamipetaiwo/10277ec440d17603bc16f8470db36ea5 to your computer and use it in GitHub Desktop.
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
function laptopRentals(times) { | |
if (times.length === 0) return 0; | |
times.sort((a, b) => a[0] - b[0]); | |
let usedLaptops = 0; | |
const startTimes = times.map((a) => a[0]).sort((a, b) => a - b); | |
const endTimes = times.map((a) => a[1]).sort((a, b) => a - b); | |
let start = 0; | |
let end = 0; | |
while (start < times.length) { | |
if (startTimes[start] >= endTimes[end]) { | |
usedLaptops--; | |
endIterator++; | |
} | |
} | |
return usedLaptops; | |
} | |
const times = [ | |
[0, 1], | |
[0, 2], | |
[0, 3], | |
[1, 4], | |
[2, 6], | |
[3, 4], | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment