🚀 Python Short and Fast (93.02%) Solution with friendly explanation 🚀
Intuition\n Describe your first thoughts on how to solve this problem. \n- The first thing to think about after reading the problem is how the low score of nums
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- The first thing to think about after reading the problem is how the low score of nums is determined and how the high score of nums is determined. The high score of nums will naturally be determined by the smallest and largest numbers in nums. What about low score of nums? How can I create the smallest low score of nums? If there are the same numbers in nums, you can get the smallest score, 0. Having thought this far, we should consider whether we can use `greedy` in this problem.\n\n- Let\'s think about whether `greedy` can be used or not.\n  There are two conditions when using `greedy`.\n\n     1. Don\u2019t current choices affect future choices? (Greedy Choice Property)\n     2. When the optimal solutions of the parts are combined, they become the optimal solution of the whole. (Optimal Substructure)\n    \n- Let\'s consider what happens the moment we select two elements from nums. At that moment, the high score of nums will be determined. Because we\'re trying to find the lowest score, we won\'t let the two selected elements affect the high score of nums. (It may seem difficult, but you will understand if you look at the solution below.) What should I do with the two elements I selected? We already know the answer. All you have to do is change both elements to an \'appropriate\' number that will not affect the high score of nums and make the low score of nums definitively 0.\n\n- Does this choice satisfy two conditions? Satisfies. The moment we select two elements, the lowest high score of nums is determined. Additionally, by simply changing the two elements selected by \'appropriate\' numbers, the low score of nums can be definitively set to 0 without affecting the high score of nums. Now, while solving the problem, I will explain why the above holds true.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n- We found out that we can take a `greedy` approach in Intuition, and just pick the two elements that produce the smallest high score of nums. To make this easier, we can come up with the idea of sorting nums.\n\n    ```\n    nums.sort()\n    ```\n- Once sorted, we can more easily pick the two elements that produce the smallest high score of nums. Here we have three cases of selecting two elements.\n    ```\n    1. Changing first two elements of sorted nums.\n    2. Changing last two elements of sorted nums.\n    3. Changing both ends elements of sorted nums.\n    ```\n- If you think about it a little, you can see why these three cases. The high score of nums is the difference between the largest and smallest numbers in nums, so you should focus on both ends of the sorted nums. At this time, the number of cases in which both ends can be changed is the above three methods.\n\n- Now it\'s time to change. However, you can think of it as excluding it rather than changing it. Because, as mentioned above, the two elements you choose to change will each be changed to the same \'appropriate\' number, so you don\'t have to worry about it. A \'appropriate\'  number is a number that does not affect either end of the sorted nums, that is, is neither smaller nor larger than the min and max of the sorted nums. Therefore, it does not affect the high score of nums, while the low score of nums is 0. I think you now understand what was explained in Intuition.\n\n- Let\'s find the three high scores of nums using the three methods above.\n    ```\n    1. nums[-1]-nums[2] # Excluding first two elements of sorted nums.\n    2. nums[-3]-nums[0] # Excluding last two elements of sorted nums.\n    3. nums[-2]-nums[1] # Excluding both ends elements of sorted nums.\n    ```\n- Now you just need to find the min of the three high scores of nums.\n    ```\n    min(nums[-1]-nums[2],nums[-3]-nums[0],nums[-2]-nums[1])\n    ```\n    We don\'t need to abs because the nums was sorted and 1 <= nums[i] <= 10^(9).\n    ## This is it! All we have to do is return this result.\n\n\n- Additionally, if you want to speed up a bit, you can add a conditional statement.\n    ```\n    if len(nums) is 3: return 0\n    ```\n   Did you notice why? Changing two elements to be equal to the remaining elements, the answer is 0.\n    There is no need to add this conditional statement, but it shortens runtime.\n\n# Complexity\n- Time complexity\n Timsort `sort()`\nbest case : $$O(n)$$\nworst case : $$O(n log n)$$\n\n\n\n- Space complexity:\nbest case : $$O(1)$$\nworst case : $$O(n)$$\n\n# Code\n```\nclass Solution:\n    def minimizeSum(self, nums: List[int]) -> int:\n        if len(nums) is 3: return 0\n        nums.sort()\n        return min(nums[-1]-nums[2],nums[-3]-nums[0],nums[-2]-nums[1])\n```
['Python3']