C++ || Intuitive || Beginner Friendly || ✅
\n\n# Code\n\nclass Solution {\npublic:\n    int largestSumAfterKNegations(vector<int>& nums, int k) {\n        sort(nums.begin(), nums.end());\n        int i=0
\n\n# Code\n```\nclass Solution {\npublic:\n    int largestSumAfterKNegations(vector<int>& nums, int k) {\n        sort(nums.begin(), nums.end());\n        int i=0;\n        for ( i = 0; i < nums.size(); i++) {\n            if (nums[i] < 0 && k > 0) { // Converting all negatives into positives\n                nums[i] = -nums[i];\n                k--;\n            }\n            else\n            break;\n        }\n        if (k > 0) { \n            sort(nums.begin(),nums.end()); // Again SORTING because now array is changed as we have changed all negatives into positives\n            while (k > 0) {\n                nums[0] = -nums[0]; // Applying the remaining K operation only on the first element\n                k--;\n            }\n        }\n        int sum = accumulate(nums.begin(), nums.end(), 0);\n        return sum;\n    }\n};\n```
['Array', 'Greedy', 'C++']