🔥 [LeetCode The Hard Way] 🔥 Explained Line By Line
\uD83D\uDD34 Check out LeetCode The Hard Way for more solution explanations and tutorials. \n\uD83D\uDFE0 Check out our Discord Study Group for live discussion.
\uD83D\uDD34 Check out [LeetCode The Hard Way](https://wingkwong.github.io/leetcode-the-hard-way/) for more solution explanations and tutorials. \n\uD83D\uDFE0 Check out our [Discord Study Group](https://discord.gg/Nqm4jJcyBf) for live discussion.\n\uD83D\uDFE2 Give a star on [Github Repository](https://github.com/wingkwong/leetcode-the-hard-way) and upvote this post if you like it.\n\uD83D\uDD35 Check out [YouTube Channel](https://www.youtube.com/@leetcodethehardway) if you are interested.\n\n---\n\n```cpp\n// the idea is to change two numbers to an existing number \n// so that the low score will be always 0.\n// to minimize the high score, we can either choose \n// - 2 biggest numbers\n// - 2 smallest numbers, or \n// - 1 biggest and 1 smallest\n// we just take the min of them\nclass Solution {\npublic:\n    int minimizeSum(vector<int>& nums) {\n        int n = nums.size();\n        sort(nums.begin(), nums.end());\n        return min({\n            // choose the biggest 2\n\t\t\t// now nums[n - 3] becomes the biggest\n\t\t\t// and nums[0] is still the smallest\n            abs(nums[n - 3] - nums[0]),\n            // choose the smallest & the biggest\n\t\t\t// now nums[n - 2] becomes the biggest\n\t\t\t// and nums[1] becomes the smallest\n            abs(nums[n - 2] - nums[1]), \n            // choose the smallest 2\n\t\t\t// now nums[n - 1] is still the biggest\n\t\t\t// and nums[2] becomes the smallest\n            abs(nums[n - 1] - nums[2])\n        });\n    }\n};\n```
['C', 'Sorting']