You are viewing a single comment's thread. Return to all comments →
Just O(n) time and O(log(n)) space complexity
static int getMinimumCost(int k, int[] c) { List<Integer> prices= Arrays.stream(c).boxed().collect(Collectors.toList()); Collections.sort(prices,Comparator.reverseOrder()); int purchasedflowers=0; int minimumcost=0; for(int i =0;i<c.length;i++){ minimumcost+=prices.get(i)*(purchasedflowers+1); if ((i+1)%k==0) { purchasedflowers++; } } return minimumcost;
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 →
Just O(n) time and O(log(n)) space complexity