C++ sort and recursion with explanation
\nclass Solution {\npublic:\n    int minDifference(vector<int>& nums) {\n        // Sort the array first. Then for each move we have 2 options:\n        // 1) M
```\nclass Solution {\npublic:\n    int minDifference(vector<int>& nums) {\n        // Sort the array first. Then for each move we have 2 options:\n        // 1) Move the smallest number to the next larger number, OR\n        // 2) Move the largest number to the next smaller number.\n        // We need to compare the difference of 1) and 2), and choose the minimum value.\n        sort(nums.begin(), nums.end());\n        return minDifference(nums, 3, 0, nums.size() - 1);\n    }\n    \nprivate:\n    int minDifference(const vector<int>& nums, int moves, int left, int right)\n    {\n        if (left > right)\n        {\n            return 0; // all elements are equal\n        }\n        \n        if (moves == 0)\n        {\n            return nums[right] - nums[left]; // no more moves\n        }\n        \n        int n1 = minDifference(nums, moves - 1, left + 1, right); // move smallest to the next larger\n        int n2 = minDifference(nums, moves - 1, left, right - 1); // move largest to the next smaller\n        return n1 < n2 ? n1 : n2;\n    }\n};\n```
[]