🔥 [Python 3] Min Heap for negative values with comments, beats 80% 🥷🏼
\nclass Solution:\n    def largestSumAfterKNegations(self, nums: List[int], k: int) -> int:\n        # if k <= n(count of negative numbers )=> need make highest
```\nclass Solution:\n    def largestSumAfterKNegations(self, nums: List[int], k: int) -> int:\n        # if k <= n(count of negative numbers )=> need make highest negative values positive (here using heap for this)\n        # if k > n(count of negative numbers) and k-n is odd => need make all negative numbers positive and minVal make negative\n        heap, res, minVal = [], 0, 101\n\n        for n in nums:\n            if n > 0: res += n\n            elif n < 0: heappush(heap, n)\n            minVal = min(minVal, abs(n))\n\n        # make highest negative values positive while k opertions available\n        while heap and k > 0:\n            res += -heappop(heap) #add negative value\n            k -= 1\n        # if still exists negative value, just add them to final sum\n        if heap:\n            res += sum(heap)\n        # if k > 0 and it\'s odd need make minVal negative (if 0 exists it will be smalles value)\n        if k % 2:\n            res = res - 2 * minVal\n        \n        return res\n\n```
['Heap (Priority Queue)', 'Python', 'Python3']