You are viewing a single comment's thread. Return to all comments →
I would recommend to skip the listcomprehension and go for a generator expression instead to save some time and memory:
def getMinimumCost(k, c): return sum((v * (i // k + 1) for i, v in enumerate(sorted(c, reverse=True))))
or for readability:
def getMinimumCost(k, c): c.sort(reverse=True) return sum((v * (i // k + 1) for i, v in enumerate(c)))
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 →
I would recommend to skip the listcomprehension and go for a generator expression instead to save some time and memory:
or for readability: