Sort array and quickly check 3 cases | Time Complexity O(nlogn)
just sort the array.\n\nnow we have 4  possible combinations of cases:\n1. we can change first 3 elemenet with 4th element of array.\n2. we can change Last 3 el
just **sort** the array.\n\n**now we have 4  possible combinations of cases**:\n1. we can change first 3 elemenet with 4th element of array.\n2. we can change Last 3 elemenet with 4th last element.\n3. we can change First 2 element with with 3rd element and last element with 2nd last element.\n4. we can change Last 2 element with 3rd last element and 1st element with 2nd element.\n\nJust find out all 4 possible combinations and return miniumn our of it.\n\n\n```\nclass Solution {\npublic:\n    int minDifference(vector<int>& nums) {\n        int len=nums.size();\n        \n        if(len < 5)\n             return 0;\n        \n        sort(nums.begin(), nums.end());\n        \n        int min1= min( nums[len-1]-nums[3], nums[len-4]-nums[0] );\n        \n        int min2= min(nums[len-2]-nums[2], nums[len-3]-nums[1]);\n        \n        return min( min1, min2);\n    }\n};\n```
['C', 'Sorting']