Java Brutal Force
I don\'t think this should be an easy quesiton.\n\n    public int largestSumAfterKNegations(int[] A, int K) {\n        int m = A.length, neg = 0, min = Integer.
I don\'t think this should be an easy quesiton.\n```\n    public int largestSumAfterKNegations(int[] A, int K) {\n        int m = A.length, neg = 0, min = Integer.MAX_VALUE, sum = 0;\n        for (int n : A) {\n            if (n < 0) neg++;\n            else min = Math.min(n, min);  //find the min to keep turning;\n            sum += n;\n        }\n        if (neg != 0) {\n            if (neg > K) { // find the smallest negs to turn to positive;\n                PriorityQueue<Integer> pq = new PriorityQueue<>((a, b) -> b - a);  // min queue\n                for (int n : A) {\n                    if (n < 0) pq.offer(n);\n                    if (pq.size() > K) pq.poll();\n                }\n                while (!pq.isEmpty()) sum -= 2 * pq.poll();\n                return sum;\n            }\n            K -= neg;  // turn all neg to positive;\n            for (int n : A) {\n                if (n < 0) {\n                    n *= -1;\n                    sum += n * 2;\n                }\n                min = Math.min(n, min);\n            }\n        }\n        if (K % 2 == 0) return sum;\n        return sum - 2 * min;\n    }\n```
[]