Skip to content

Instantly share code, notes, and snippets.

@Toscan0
Last active April 5, 2023 12:24
Show Gist options
  • Save Toscan0/886cadef1945c0e0a2ae16a4b41ba6f2 to your computer and use it in GitHub Desktop.
Save Toscan0/886cadef1945c0e0a2ae16a4b41ba6f2 to your computer and use it in GitHub Desktop.
Binge-Watching code challenge - Solution
// Max 3 hours per day
// 1.01 < movies durations < 3
const durations = [1.9, 1.04, 1.25, 2.5, 1.75];
const getMinDays = function (durations) {
var nDays = 0, startIdx = 0;
durations.sort()
for (let i = (durations.length - 1) ; i >= startIdx; i--){
if(durations[i] >= 2) {
nDays++;
}
else {
if(startIdx !== i && durations[startIdx] + durations[i] <= 3) {
startIdx++;
}
nDays++;
}
}
return nDays;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment