You are viewing a single comment's thread. Return to all comments →
Solution in JAVA
// Complete the getMinimumCost function below. static int getMinimumCost(int k, int[] c) {
Arrays.sort(c); int res=0; int m=0;int counter=0; int i=c.length-1; for(;i>=0;i--) { if(counter%k==0 && counter>0){ counter=0; m++; } System.out.println(i+" "+m+" "+counter); res=res+(m+1)*c[i]; counter++; System.out.println(res); } return res; }
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 →
Solution in JAVA
// Complete the getMinimumCost function below. static int getMinimumCost(int k, int[] c) {