Simple Greedy Approach | My screen recording
\nclass Solution {\npublic:\n    int minDifference(vector<int>& nums) {\n        \n        // if the size is smaller than 4 than we can easily make each of them
```\nclass Solution {\npublic:\n    int minDifference(vector<int>& nums) {\n        \n        // if the size is smaller than 4 than we can easily make each of them equal and hence min possible difference is zero\n        if(nums.size() <= 3)\n            return 0;\n        \n        int n = nums.size();\n        \n        // sort the array in increasing order because we want to consider few of the largest and smallest numbers.\n        sort(nums.begin(), nums.end());\n        \n        \n        \n        // Now idea is to try greedy. First of all we must agree that the values \n\t\t// which we will be changing should be either from left end or right end, \n\t\t// As there is no gain if we start changing values from middle of the array. \n\t\t// And hence we can try to make these 3 moves in all following possible \n\t\t// ways and choose the one which gives the best answer. \n        // And because there are only 3 moves so total possibilities will be exactly 4.\n        \n        int ans = INT_MAX; // initialize the answer with INT_MAX.\n        \n        // CASE 1: when changing only from beg\n        ans = min(ans, abs(nums[3] - nums[n - 1]));\n        \n        // CASE 2: when change two from beg and one from last\n        ans = min(ans, abs(nums[2] - nums[n - 2]));\n        \n        // CASE 3: when change only from beg and two from last\n        ans = min(ans, abs(nums[1] - nums[n - 3]));\n        \n        // CASE 4: when change all the values from last\n        ans = min(ans, abs(nums[0] - nums[n - 4]));\n        \n        return ans;\n    }\n};\n```\n\nIncase if you\'re interested in watching a boring recording \n\nhttps://youtu.be/8TgT77Ijei8\n
[]