Karan Kumar a year agoconst solve = (workers, tasks) => { return Math.ceil(tasks.reduce((x,y) => x+y)/workers) }; CancelSubmit
Forges2 years agoconst solve = (workers, tasks) => { return Math.ceil(tasks.reduce((acc, cur) => acc + cur, 0) / 2); }; CancelSubmit
Ergonomic compress2 years agoHere is how I solved mine. Basically just resorting the workers array so that the most available worker always took the most work first. const solve = (workers, tasks) => { let workerArray = new Array(workers).fill(0) let sortedTasks = tasks.sort((a,b) => a > b ? -1 : 1) while(sortedTasks.length){ workerArray[0] += sortedTasks.shift() workerArray = workerArray.sort((a,b) => a > b ? 1: -1) } return Math.max(...workerArray) }; CancelSubmit
Comments
Karan Kumar a year ago
Forges2 years ago
Ergonomic compress2 years ago
Here is how I solved mine. Basically just resorting the workers array so that the most available worker always took the most work first.
const solve = (workers, tasks) => { let workerArray = new Array(workers).fill(0) let sortedTasks = tasks.sort((a,b) => a > b ? -1 : 1) while(sortedTasks.length){ workerArray[0] += sortedTasks.shift() workerArray = workerArray.sort((a,b) => a > b ? 1: -1) }
return Math.max(...workerArray) };