Explanation of the whole idea
Explanation\n\nAssume nums = [8,-1,8,-3,2,-2], k = 2\n\nTo get the LARGEST SUM we will make positive -3 and -2 as they are the SMALLEST NEGATIVE\nNUMBERS. This 
## Explanation\n```\nAssume nums = [8,-1,8,-3,2,-2], k = 2\n\nTo get the LARGEST SUM we will make positive -3 and -2 as they are the SMALLEST NEGATIVE\nNUMBERS. This finding process would be easier if we sort first:\n\n               -3,-2,-1,2,8,8 \n\nIf k were 5, first we would turn all the negative numbers to positive numbers, right?\nCause the Q asked us LARGEST SUM!\n\n               3,2,1,2,8,8 and now k = 5 - 3 = 2\n\nAs we can choose the same index multiple times SO AFTER TURNING NEGATIVE NUMBERS\nTO POSITIVE NUMBERS, OBVIOUSLY WE WILL NOW PICK THE SMALLEST NUMBER TO CHANGE IT\'S SIGN\nTO REMAINING K TIMES TO GET THE LARGEST SUM.\n\nHere the smallest number now is 1 and k = 2, so -1,1 which is same as 1 cause \n       if k is even, sign won\'t change, but if k is odd, sign will change 100%.\n```\n\n```CPP []\nclass Solution {\npublic:\n    int largestSumAfterKNegations(vector<int>& nums, int k) {\n        sort(begin(nums),end(nums));\n        for(int i=0; i<nums.size() && nums[i]<0 && k>0; i++, k--)\n            nums[i] = -nums[i];    \n\n        nums[min_element(begin(nums),end(nums))-begin(nums)] *= ((k&1) == 1? -1 : 1);\n        return accumulate(begin(nums),end(nums),0);      \n    }\n};\n```\n```python []\nclass Solution:\n    def largestSumAfterKNegations(self, nums: List[int], k: int) -> int :\n        nums.sort()\n        i = 0\n        while i<len(nums) and k>0 and nums[i]<0 :\n            nums[i] = -nums[i]\n            i, k = i+1, k-1\n        nums[nums.index(min(nums))] *= -1 if k&1 else 1\n        return sum(nums) \n```\n```\nTime complexity  : O(nlogn)\nSpace complexity : O(sort)\n```\n
['C++', 'Python3']