Last active
April 5, 2023 12:24
-
-
Save Toscan0/886cadef1945c0e0a2ae16a4b41ba6f2 to your computer and use it in GitHub Desktop.
Binge-Watching code challenge - Solution
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
// 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