Created
October 7, 2021 06:47
-
-
Save misterpoloy/836167d60fbb163e1d8ac4c58d1faec9 to your computer and use it in GitHub Desktop.
Mínimum waiting time Greedy Method
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 minimumWaitingTime(queries) { | |
let total = 0 | |
// Sort the array | |
queries.sort((a, b) => a - b) | |
for (let i = 0; i < queries.length; i++) { | |
const remainOperations = queries.length - 1 - i; | |
total += remainOperations * queries[i] | |
} | |
return total | |
} | |
// Do not edit the line below. | |
exports.minimumWaitingTime = minimumWaitingTime; |
Author
misterpoloy
commented
Oct 7, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment