JSFiddle - React, Tailwind, and code Playground
by Nabaraj Saha
JavaScript
function cookies(k, a) {
/*
* Write your code here.
*/
let total = a.reduce((acc,item)=>acc+item);
if(total<k){
return -1
}
else{
let counter = 0, j=0;
for(let i=0;i<a.length; i++){
let c = a[i];
while(c<k){
i++;
c = c>a[i]?(a[i]*1)+(c*2):(c*1)+(a[i]*2);
counter++;
}
}
return counter;
}
}
console.log(cookies(90,[13, 47, 74, 12, 89, 74, 18, 38]))