Skip to content

Instantly share code, notes, and snippets.

@olabamipetaiwo
Created November 3, 2021 19:54
Show Gist options
  • Save olabamipetaiwo/10277ec440d17603bc16f8470db36ea5 to your computer and use it in GitHub Desktop.
Save olabamipetaiwo/10277ec440d17603bc16f8470db36ea5 to your computer and use it in GitHub Desktop.
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