C++ 100% || lengthy || sorting
\nclass Solution {\npublic:\n    int largestSumAfterKNegations(vector<int>& nums, int k) {\n        int sum=0;\n        int i=0;\n        \n       sort(nums.beg
```\nclass Solution {\npublic:\n    int largestSumAfterKNegations(vector<int>& nums, int k) {\n        int sum=0;\n        int i=0;\n        \n       sort(nums.begin(),nums.end());\n       while(i<nums.size()&&(k>0&&nums[i]<=0)){\n           if(nums[i]<0){\n               nums[i]=-nums[i];\n               k--;\n           }\n           else {\n               k=0;\n               break;\n           }\n           i++;\n           }\n        while(i<nums.size()&&(k>0&&nums[i]>0)){\n            if(i!=0){\n                if(nums[i]<=nums[i-1]){\n                    if(k%2!=0){\n                        nums[i]=-nums[i];\n                        k=0;\n                    }\n                }\n                if(nums[i]>nums[i-1]){\n                    if(k%2!=0){\n                        nums[i-1]=-nums[i-1];\n                        k=0;\n                    }\n                }\n            }\n            else{\n                if(k%2!=0){\n                    \n                    nums[i]=-nums[i];\n                    cout<<nums[i]<<endl;\n                    k=0;\n                }\n            }\n            i++;\n}\n            if(k%2!=0){\n                nums[nums.size()-1]=-nums[nums.size()-1];\n                k=0;\n            }      \n        \n        for(int j=0;j<nums.size();j++){\n            sum+=nums[j];\n        }\n        return sum;\n       }\n    };\n\n```
[]