Java: Simple Greedy Solution Explained, Beats ~ 100%
The intution is - \n1. Sort the array.\n2. Check if first element of the array is positive.\n\ti. If K is even, don\'t modify anything.\n\tii. Else, modify the 
The intution is - \n1. Sort the array.\n2. Check if first element of the array is positive.\n\ti. If K is even, don\'t modify anything.\n\tii. Else, modify the lowest element.\n3. Else, mark all -ve elements positive for a given K.\n4. If K after operations is not even then, mark the lowest element -ve.\n5. Sum up and return.\n\n\n```\nclass Solution {\n    public int largestSumAfterKNegations(int[] A, int K) {\n        Arrays.sort(A);\n        int sum = 0;\n        if (A[0] >= 0 && K % 2 != 0) {\n            A[0] = - A[0];\n        } else if (A[0] < 0 ) { //&& K % 2 == 0) {\n            int change = 0;\n            while (K > 0 && A[change] < 0 && change < A.length) {\n                A[change] = - A[change++];\n                K--;\n            }\n            if (K % 2 != 0) {\n                int index = A[change] < A[change - 1] ? change : change - 1;\n                A[index] = - A[index];\n            }\n        }\n        for (int val : A) sum += val;\n        return sum;\n    }\n}\n```\n\nIf you liked the post please do upvote and any suggestions are most welcome.\nPS: I see a few people posting solution with PriorityQueue, which is awesome, however, the question says \'modify the array\'.
['Array', 'Greedy', 'Sorting', 'Java']