Easy to Understand Apprach without cases
Basic idea is to sort the array based on their absolute value and then start taking ones having greater absolute value. If we encouter a negative element, we ca
Basic idea is to sort the array based on their absolute value and then start taking ones having greater absolute value. If we encouter a negative element, we can use one negation to negate it and add it\'s absolute value, otherwise we have no other option, we have to take it\'s original value. In the last, we will check if we have some K left i.e. we have to negate more elements. Most optimal choice here is to negate the minimum absolute value element. If K is even, it will not have any effect otherwise we have to subtract it\'s *absolute value* twice from our sum as we have taken it once before also.\n```\nclass Solution {\npublic:\n    int largestSumAfterKNegations(vector<int>& A, int K) {\n        int n = A.size();\n        auto cmp = [](int a, int b) {\n            return abs(a) > abs(b);\n        };\n        \n        sort(A.begin(), A.end(), cmp);\n        int sum = 0;\n        for(int i = 0; i < n; i++) {\n            if(A[i] < 0 && K > 0) {\n                sum += -A[i];\n                K--;\n            }\n            else {\n                sum += A[i];\n            }\n        }\n        \n        if(K&1) {\n            sum -= 2*(abs(A[n-1]));\n        }\n        return sum;\n    }\n};\n```
['Greedy', 'C']