100 % faster sol C++
The time complexity of this approach is O(n+n log n).\nhope you will find it helpful.\n\nint largestSumAfterKNegations(vector<int>& nums, int k) {\n       sort(
The time complexity of this approach is O(n+n log n).\nhope you will find it helpful.\n```\nint largestSumAfterKNegations(vector<int>& nums, int k) {\n       sort(nums.begin(),nums.end());\n        int i=0,sum=0;\n        while(i<nums.size())\n        {\n            if(nums[i]<0&& k>0)\n            {\n                nums[i]*=(-1);\n                k--;\n            }\n            else if(nums[i]>=0)\n                break;\n            i++;\n        }\n        if(k%2!=0)\n        {\n            sort(nums.begin(),nums.end());\n                nums[0]*=(-1);           \n        }               \n        for(auto a:nums)\n            sum+=a;\n        return sum; \n    }\n```
['Greedy', 'Sorting']