c++ 10 lines O(NlogN) time/ O(1) space use only sort+comparison (beat 99% time/100% space)
\nclass Solution {\npublic:\n    int largestSumAfterKNegations(vector<int>& A, int K) {\n        \n        sort(A.begin(), A.end());\n        int minIdx = 0;\n 
```\nclass Solution {\npublic:\n    int largestSumAfterKNegations(vector<int>& A, int K) {\n        \n        sort(A.begin(), A.end());\n        int minIdx = 0;\n        // Do K steps\n        for(int i = 0; i < K; i++){\n            // change the sign of the smallest element\n            A[minIdx] = -A[minIdx];\n            if(minIdx == A.size()-1  || A[minIdx] > A[minIdx + 1])  minIdx++;\n        }\n        int sum = 0;\n        for(auto a: A)  sum += a;\n        return sum;\n    }\n};\n```
['C']