O(N) -> 95% | best solution c++
Intuition\n Describe your first thoughts on how to solve this problem. \nthe min 2 and max 2 elements are responsible to make the high score more high and the l
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nthe min 2 and max 2 elements are responsible to make the high score more high and the low score can be set to zero by making two min elements equal\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\napproach 1-> first sort the array and then out of 3 options{\n1-> last element - arr[2]\n2-> arr[size-3] - arr[0]\n3-> arr[size-2] - arr[1]\n}\ndont forget to use absolute values of this 3\nreturn the minimum of 3;\n\napproach 2-> instead of sotring in O(N*Log N), traverse the array and find 3 minimum elements and 3 maximum elements of array and then find min of this 3{\n1-> max1-min3\n2-> max2-min2\n3-> max3-min1\n}\ndont forget to use absolute values of this 3\nreturn minimum of this 3\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int minimizeSum(vector<int>& a) {\n        // sort(nums.begin(),nums.end());\n        int max1=INT_MIN,max2=INT_MIN,min1=INT_MAX,min2=INT_MAX,max3=INT_MIN,min3=INT_MAX;\n        for(int i=0;i<a.size();i++){\n            if(a[i]>max1){\n                max3=max2;\n                max2=max1;\n                max1=a[i];\n            }\n            else if(a[i]>max2){\n                max3=max2;\n                max2=a[i];\n            }else if(a[i]>max3){\n                max3=a[i];\n            }\n            if(a[i]<min1){\n                min3=min2;\n                min2=min1;\n                min1=a[i];\n            }else if(a[i]<min2){\n                min3=min2;\n                min2=a[i];\n            }\n            else if(a[i]<min3){\n                min3=a[i];\n            }\n        }\n        return min(abs(max1 - min3),min(abs(max3-min1),abs(max2-min2)));\n    }\n};\n```
['C++']