[Java/C++/Python] Sort
Explanation\n@codePower:\nIn case someone needs an explanation:\n1- sort the numbers in ascending order\n2- flip all the negative numbers, as long as k > 0\n3- 
## **Explanation**\n@codePower:\nIn case someone needs an explanation:\n1- sort the numbers in ascending order\n2- flip all the negative numbers, as long as k > 0\n3- find the sum of the new array (with flipped numbers if any) and keep track of the minimum number\n4- Now for the return statement\n\n`res` is the total sum of the new array\n`K % 2` check if the remaining `K` is odd.\n\nBecause if it\'s even, it will have no effect\n(we will flip a number and then get it back to the original)\n\nIf it\'s odd,\nflip the minimum number and remove twice its value from the result\n(twice because we already added it as positive in our sum operation)\n<br>\n\n## **Complexity**\nTime `O(NlogN)` for sorting.\nSpace `O(1)` extra space, in-place sort\n\nTime can be easily improved to `O(N)`,\nby quick selecting the `k`th negative.\n<br>\n\n**Java**\n```java\n    public int largestSumAfterKNegations(int[] A, int K) {\n        Arrays.sort(A);\n        for (int i = 0; K > 0 && i < A.length && A[i] < 0; ++i, --K)\n            A[i] = -A[i];\n        int res = 0, min = Integer.MAX_VALUE;\n        for (int a : A) {\n            res += a;\n            min = Math.min(min, a);\n        }\n        return res - (K % 2) * min * 2;\n    }\n```\n\n**C++**\n```cpp\n    int largestSumAfterKNegations(vector<int>& A, int K) {\n        sort(A.begin(), A.end());\n        for (int i = 0; K > 0 && i < A.size() && A[i] < 0; ++i, --K)\n            A[i] = -A[i];\n        return accumulate(A.begin(), A.end(), 0) - (K%2) * *min_element(A.begin(), A.end()) * 2;\n    }\n```\n\n**Python:**\n```py\n    def largestSumAfterKNegations(self, A, K):\n        A.sort()\n        i = 0\n        while i < len(A) and i < K and A[i] < 0:\n            A[i] = -A[i]\n            i += 1\n        return sum(A) - (K - i) % 2 * min(A) * 2\n```\n
[]