Java $ms Solution
\nclass Solution {\n    public int largestSumAfterKNegations(int[] nums, int k) \n    {\n        Arrays.sort(nums);\n        int count=0;\n        int prev=0;\n
```\nclass Solution {\n    public int largestSumAfterKNegations(int[] nums, int k) \n    {\n        Arrays.sort(nums);\n        int count=0;\n        int prev=0;\n        for(int i:nums)\n        {\n            if(i<0)\n            {\n                if(k>0)\n                {\n                    count+=Math.abs(i);\n                    k--;\n                    prev = i;\n                }\n                else\n                {\n                    count+=i;\n                }\n            }\n            else if(i==0)\n            {\n                k=0;\n            }\n            else\n            {\n                if(k%2==0)\n                {\n                    count+=i;\n                    k=0;\n                }\n                else\n                {\n                    if(prev==0)\n                    {\n                        count+=(-1*i);\n                        k=0;\n                    }\n                    else\n                    {\n                        if(prev>i || Math.abs(prev)>i)\n                        {\n                            count+=(-1*i);\n                        }\n                        else\n                        {\n                            count+=prev;\n                            count+=(prev + i);\n                        }\n                        k=0;\n                    }\n                }\n            }\n        }\n        if(k%2!=0)\n        {\n            count+=(prev + prev);\n        }\n        return count;\n    }\n}\n```
['Java']