Remove Stones to Minimize the Total

Given an integer array representing piles of stones, you must perform exactly k operations. In each operation, choose any pile and remove half of the stones (rounded down). Return the minimum possible total number of stones remaining after k operations.

Constraints

  • 1 <= piles.length <= 10^5
  • 1 <= piles[i] <= 10^4
  • 1 <= k <= 10^5
Saving… · 3 lines
class Solution:
def removeStonesToMinimizeTheTotal(self, piles, k) -> int:

Console

Click Run to execute sample tests.