Java Solution || Priority Queue || Code with comments
\n// TC: O(nlogn)\nclass Solution {\n    public int largestSumAfterKNegations(int[] nums, int k) {\n        \n        // Create a priority queue and insert all 
```\n// TC: O(nlogn)\nclass Solution {\n    public int largestSumAfterKNegations(int[] nums, int k) {\n        \n        // Create a priority queue and insert all array elements in the priority queue      TC: O(n)\n        PriorityQueue<Integer> pq = new PriorityQueue<>();\n        \n        for(int num : nums)\n            pq.add(num);\n        // Do k negations by removing a minimum element k times         TC: O(log n)\n        while(k--> 0) {\n            int temp = pq.poll();   // Retrieve and remove min element\n            \n            temp *= -1;     // Modify the min element and add it back to priority queue\n            pq.add(temp);\n        }\n        \n        // Compute sum of all elements in priority queue\n        int sum = 0;\n        for(int num : pq)\n            sum += num;\n        return sum;\n    }\n}\n```
['Heap (Priority Queue)', 'Java']