We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
functiongetMinimumCost(k,c){letmin=0;// sort flowers - highest to lowestc.sort((a,b)=>(a-b<0?1:-1));for(letbuyerIdx=0;buyerIdx<k;buyerIdx++){// e.g. 3 friends = 3 buyers// with every purchase the next purchased flower gets multipliedletmultiplier=1;// to have the lowest possible multiplier on the hightest prices,// -> buy every "k" flower (flowerIdx += k) in the price-sorted arrayfor(letflowerIdx=buyerIdx;flowerIdx<c.length;flowerIdx+=k){min+=c[flowerIdx]*multiplier++;}}returnmin;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Greedy Florist
You are viewing a single comment's thread. Return to all comments →
JS