Solution with sorting and changing the edges of the array.
Intuition\n \nEven thought the math in this question looks complex, there are some things to note:\n1. low compelxity doesnt matter, since you can always change
# Intuition\n<!-- \nEven thought the math in this question looks complex, there are some things to note:\n1. low compelxity doesnt matter, since you can always change numbers to the a same number in the array (or just both of them to the same number), resulting it to be 0.\n2. that being said, minimizing the high Score became the task.\n3. to minimize the high score, well need to change 2 out of the 4 edges (maximum, minimum, second maximum, second minimum)\n-->\n\n# Approach\n<!--\nnote: if the array is in the length of 3, the result is always 0, and since my code fails in that specific case, i just added to return 0.\n1. sorting the array\n2. using conditions to determine which 2 of the edges to change.\nnote: once an edge changes, the code doesnt concider it an edge anymore, viewing the next one as the edge.\n\n3. the 2 changed elements are changed to the same number, which is the average of the new edges of the array, to minimize hight score, and setting low score to 0 (they become the same number).\n\n4. once changing them resorting the array to get the score.\n \n-->\n\n# Complexity\n- Time complexity:\n<!-- since im using quickSort, the worst complexity is O(n^2)\n     althought average complexity is O(n*log(n))\n -->\n\n- Space complexity:\n<!-- since im using insersionkSort, the worst complexity is O(n^2)\n     but since we are using is to sort an almost sorted array,  i   would say its more like O(n) -->\n\n# Code\n```\npublic class Solution {\n    public int MinimizeSum(int[] nums) {\n        if(nums.Length == 3)\n            return 0;\n        int[] arr = QuickSortArray(nums,0,nums.Length-1);\n\n        int min = arr[0];\n        int min2 = arr[1];\n        int max = arr[arr.Length -1];\n        int max2 = arr[arr.Length -2];\n\n        int min3 = arr[2];\n        int max3 = arr[arr.Length-3];\n\n        int maxAbsVal = Math.Abs(max3-min3);\n        bool isMax = false;\n\n        //if(Math.Abs(max - max3) > Math.Abs(min - min3)){\n            //isMax = true;\n        //}\n\n        if(Math.Abs(max - min3) > Math.Abs(min - max3)){\n            isMax = true;\n        }\n        if(isMax){ //max is changing\n            if(Math.Abs(min - max3) > Math.Abs(max2 - min2)){\n            //min and max are changing\n            min = (max2+min2)/2;\n            max = min;\n        }\n        else{\n            //max and max2 are changing\n            max2 = (min+max3)/2;\n            max = min;\n        \n        }\n        }\n        else{//min is changing\n            if(Math.Abs(max - min3) > Math.Abs(min2 - max2)){\n            //min and max are changing\n            min = (max2+min2)/2;\n            max = min;\n        }\n        else{\n            //min and min2 are changing\n            min = (max+min3)/2;\n            min2 = min;\n        }\n\n\n        }\n\n        arr[0] = min;\n        arr[1] = min2;\n        arr[arr.Length -1] =  max;\n        arr[arr.Length -2] = max2;\n        InsersionSort(arr);\n\n        return (Math.Abs(arr[arr.Length-1]- arr[0]));\n    }\n\n    void InsersionSort(int[] arr)\n    {\n        int n = arr.Length;\n        for (int i = 1; i < n; ++i) {\n            int key = arr[i];\n            int j = i - 1;\n\n            // Move elements of arr[0..i-1],\n            // that are greater than key,\n            // to one position ahead of\n            // their current position\n            while (j >= 0 && arr[j] > key) {\n                arr[j + 1] = arr[j];\n                j = j - 1;\n            }\n            arr[j + 1] = key;\n        }\n    }\n    public int[] QuickSortArray(int[] array, int leftIndex, int rightIndex)\n{\n    var i = leftIndex;\n    var j = rightIndex;\n    var pivot = array[leftIndex];\n\n    while (i <= j)\n    {\n        while (array[i] < pivot)\n        {\n            i++;\n        }\n        \n        while (array[j] > pivot)\n        {\n            j--;\n        }\n\n        if (i <= j)\n        {\n            int temp = array[i];\n            array[i] = array[j];\n            array[j] = temp;\n            i++;\n            j--;\n        }\n    }\n    \n    if (leftIndex < j)\n        QuickSortArray(array, leftIndex, j);\n\n    if (i < rightIndex)\n        QuickSortArray(array, i, rightIndex);\n\n    return array;\n}\n}\n```
['C#']