Easy understanding, Commented C++ solution with sort and sliding window
\n// Idea: \n//    1. Chaning a number to any value is the same as removing them from array,\n//       in the sense of calculating min difference.\n//    2. Try
```\n// Idea: \n//    1. Chaning a number to any value is the same as removing them from array,\n//       in the sense of calculating min difference.\n//    2. Try to simplify the question, what if you were asked to change one value\n//       from a sorted array and get the min difference of largest and smallest value of a sorted array?\n//    3. You will probably get the answer of removing either the front or the end.\n//    4. How about changing 2 numbers? You will either need to remove the first 2, last 2 or 1 from each end.\n//    5. Notice the pattern here, it is a sliding window. This can also be applied in our case.\n\n// Sliding window for changing 3 elements\n// [x, x, x, 4, 5, 6] -> diff = 6 - 4 = 2\n// [x, x, 3, 4, 5, x] -> diff = 5 - 3 = 2\n// [x, 2, 3, 4, x, x] -> diff = 4 - 2 = 2\n// [1, 2, 3, x, x, x] -> diff = 3 - 1 = 2\n// Ans: 2\n\nclass Solution {\npublic:\n    // Time: O(nlogn), n = nums.size()\n    // Space: O(1)\n    int minDifference(vector<int>& nums) {\n        int i = 0;\n        int j = nums.size() - 1;\n        \n        int k = 3;\n        \n        if (nums.size() <= k + 1) {\n            return 0;\n        }\n        \n        sort(nums.begin(), nums.end()); // time: O(nlogn)\n        \n        int diff = nums.back() - nums[k];\n        int res = diff;\n        \n        for (int i = 1; i <= k; i++) { // time: O(k), k = 3, since k is bounded, thus O(1)\n            diff = nums[nums.size() - 1 - i] - nums[k - i];\n            res = min(diff, res);\n        }\n        \n        return res;\n    }\n};\n```
['C', 'Sliding Window', 'Sorting', 'C++']