Very Simple and Beginner Friendly with Explanation | C++
Intuition\n Describe your first thoughts on how to solve this problem. \nWe have to partition nums in such a max(nums1) - min(nums2) id minimum.\nWe know that i
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe have to partition `nums` in such a `max(nums1)` - `min(nums2)` id minimum.\nWe know that in an `Sorted Array` the minimum difference between any two pairs `(i, j)` of the array would be minimum difference between `(i, i + 1)`.\nEx: `1,2,3,4,5` diff between `1 & 2` is always less than `1,3` & `1, 4` & `1,5`. Similarly for all adjacent pairs.\n\nAssume a Sorted array `....a,b,c,d.....` if we choose `c` to be minium of `nums2` and `b` to be maximum of `nums1`.\nWe can do this by partitioning `.....ab` & `cd.....`.\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nPartition at each index and find minimum.\n`....a` & `bcd...` (b - a)\n`....ab` & `cd...` (c - b)\n`....abc` & `d...` (d - c)\n\n# Complexity\n- Time complexity:`O(N * Log(N))`\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: `O(1)`\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int findValueOfPartition(vector<int>& nums) {\n        int ans = 1e9;\n        sort(nums.begin(), nums.end());\n        for(int i = 1; i < nums.size(); i++){\n            ans = min(ans, nums[i] - nums[i - 1]);\n        }\n        return ans;\n    }\n};\n```
['Array', 'Sorting', 'C++']