Optimal + Easy sol | Time - o(nlogn) | Easy Vid Explanation also
https://youtu.be/wQUB0lhYK6Y\n# Intuition\n Describe your first thoughts on how to solve this problem. \nThe goal is to minimize the difference between the maxi
https://youtu.be/wQUB0lhYK6Y\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe goal is to minimize the difference between the maximum and minimum values in the array after making at most 3 moves. Since we can make up to 3 changes, effectively we can remove up to 3 elements from either end (start or end) of the sorted array to minimize the difference. The main insight is to try out the combinations of removing elements from both ends and find the minimum possible difference.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Sort the array nums.\n2. If the size of the array n is less than or equal to 4, return 0 since we can remove all elements to get an empty array which results in a difference of 0.\n3. Calculate the minimum difference by removing elements in these combinations:\n- Remove the last 3 elements.\n- Remove the first 3 elements.\n- Remove the first 1 and last 2 elements.\n- Remove the first 2 and last 1 elements.\n\nThe result will be the minimum of these differences.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n- \uD835\uDC42(\uD835\uDC5Blog\uD835\uDC5B)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n- O(1)\n\n# Code\n```\nclass Solution {\npublic:\n    int minDifference(vector<int>& nums) {\n\n        sort(nums.begin(),nums.end());\n\n        int minVal = INT_MAX;\n\n        int n = nums.size();\n\n        if(n <= 4) return 0;\n\n        minVal = min(minVal, nums[n-4] - nums[0]);\n        minVal = min(minVal, nums[n-1] - nums[3]);\n        minVal = min(minVal, nums[n-2] - nums[2]);\n        minVal = min(minVal, nums[n-3] - nums[1]);\n\n        return minVal;\n        \n    }\n};\n```
['C++']