Skip to content

Instantly share code, notes, and snippets.

@misterpoloy
Created October 7, 2021 06:47
Show Gist options
  • Save misterpoloy/836167d60fbb163e1d8ac4c58d1faec9 to your computer and use it in GitHub Desktop.
Save misterpoloy/836167d60fbb163e1d8ac4c58d1faec9 to your computer and use it in GitHub Desktop.
Mínimum waiting time Greedy Method
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;
@misterpoloy
Copy link
Author

screenshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment