1005. Simple solution | Beats 91%
Code\n\nclass Solution:\n    def largestSumAfterKNegations(self, nums: List[int], k: int) -> int:\n        nums.sort()\n        last_negative, last_ind = nums[0
# Code\n```\nclass Solution:\n    def largestSumAfterKNegations(self, nums: List[int], k: int) -> int:\n        nums.sort()\n        last_negative, last_ind = nums[0], 0\n        for x, item in enumerate(nums):\n            if k <= 0 or item == 0: break\n            if item < 0:\n                last_negative = -item\n                last_ind = x\n                nums[x] = -1 * item\n                k -= 1\n            elif item > 0:\n                if k % 2 == 0: break\n                else:\n                    if item > last_negative:\n                        nums[last_ind] = -1* last_negative\n                        break\n                    else:\n                        nums[x] = -item\n                        break\n        else:\n            nums[last_ind] = (-1**k)* last_negative\n        return sum(nums)\n\n\n```
['Array', 'Math', 'Greedy', 'Sorting', 'Python3']