Java | Simple | Explained
Idea:\n To maximize the sum, negate the negatives and then the smallest number\n Negation of negation of n gives back n. \n This means if k is even, then we can
**Idea:**\n* To maximize the sum, negate the negatives and then the smallest number\n* Negation of negation of n gives back n. \n* This means if k is even, then we can exhaust it on the smallest int without changing it. So ignore even value k after loop  \n* If k is odd, only then you need to actually negate the smallest int for maximum sum\n>**T/S:** O(n lg n)/O(1), where n = size(nums) (ignored extra space of Arrays.sort)\n```\npublic int largestSumAfterKNegations(int[] nums, int k) {\n\tArrays.sort(nums);\n\tvar minIndex = 0;\n\t\n\tfor (var i = 0; i < nums.length && k > 0; i++) {\n\t\tif (nums[i] < 0) {\n\t\t\tnums[i] *= -1;\n\t\t\tk--;\n\t\t}\n\t\tif (nums[minIndex] > nums[i])\n\t\t\tminIndex = i;\n\t}\n\n\tif ((k & 1) == 1)\n\t\tnums[minIndex] *= -1;\n\t\t\n\treturn Arrays.stream(nums)\n\t\t\t\t .sum();\n}\n```\n***Please upvote if this helps***
['Java']