Maximize Sum Of Array After K Negations Solution in C++
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(nlogn)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n# Code\n```\nclass Solution {\npublic:\n    int largestSumAfterKNegations(vector<int>& nums, int k) {\n        int i, j=0, sum=0;\n        sort(nums.begin(), nums.end());\n        for(i=0 ; i<k ; i++)\n        {\n            if(nums[j]<0)\n            {\n                nums[j] *= (-1);\n                if(j<nums.size()-1 && nums[j+1]<abs(nums[j]))\n                    j++;\n            }\n            else if(nums[j]>=0)\n            {\n                nums[j] *= -1;\n            }\n        }\n        sum = accumulate(nums.begin(), nums.end(), 0);\n        return sum;\n    }\n};\n```\n![upvote new.jpg](https://assets.leetcode.com/users/images/4615bd62-f688-4d57-965e-a6968997c323_1683460834.4019096.jpeg)\n
['C++']