You are viewing a single comment's thread. Return to all comments →
yup this problem was super easy.
static int getMinimumCost(int k, int[] c) { Arrays.sort(c); int counter = 0; int pre = 0; int minCost = 0; for(int i=c.length-1; i>=0; i--) { while(i>=0&&counter<k) { minCost += c[i]*(pre+1); counter++; i--; } i++; counter = 0; pre++; } return minCost; }
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 →
yup this problem was super easy.