Gary Lai
  • Home
  • About
Sign in Subscribe

1962. Remove Stones to Minimize the Total

Last updated on  Mar 30, 2025

1962. Remove Stones to Minimize the Total

class Solution:
    def minStoneSum(self, piles: List[int], k: int) -> int:
        heap = []
        for pile in piles:
            heapq.heappush(heap, -pile)
        
        while k > 0:
            top = heapq.heappop(heap)
            heapq.heappush(heap, floor(top / 2))
            k -= 1
        
        return sum([-pile for pile in heap])
Previous 270. Closest Binary Search Tree Value
Next 480. Sliding Window Median
Gary Lai © 2025
  • Sign up
Powered by Ghost