Javascript w/ detailed explanation
Intuition\nConsider an example nums=[23, 13, 8, 16, 5, 11], and suppose we\'re looking at the element 11 to play the role of max(nums1). For now, we don\'t know
# Intuition\nConsider an example `nums=[23, 13, 8, 16, 5, 11]`, and suppose we\'re looking at the element `11` to play the role of `max(nums1)`. For now, we don\'t know if it is indeed `max(nums1)`, we\'re just assuming for now. \n\nWe can see that to minimize the partition value, `min(nums2)` should be `13`, which would yield a partition value of `2`. We can see this by individually looking at every element apart from `11` and calculating the partition value by hand. However, we can do this more efficiently by looking at the sorted version: `nums=[5, 8, 11, 13, 16, 23]`. Notice that partition value gets larger as the element we choose to play the role of `min(nums2)` is further away from `11` in the sorted array. For example, choosing `5` to be `min(nums2)` would yield a partition value of `6`, and choosing `16` would yield a partition value of `5`. So, to find the minimal partition value given that `11` plays the role of `max(nums1)`, we only need to consider the partition value when `11`\'s adjacent elements (in the sorted array) to play the role as `min(nums2)`. In our example, the `min(nums2)` is to the right adjacent element.\n\nKnowing this, to solve the problem, we can start by sorting the array first. Then, iterate over each element `ei` and consider it to play the role of `max(nums1)`. `min(nums2)` could either be its left adjacent element or right adjacent element. \n`e1,e2,e3, ..., e_(i-1), ei, e_(i+1), ..., en`\n\nIf `min(nums2)` is its right adjacent element, then the array can be partitioned as \n``nums1=[e1,e2,e3,...,ei], \nnums2=[e_(e+1), e_(i+2), ... en]``\n\nIf `min(nums2)` is its left adjacent element, then the array can be partitioned as \n``nums1=[e1,e2,e3,...,e_(i-2),ei], \nnums2=[e_(i-1), e_(e+1), e_(i+2), ... en]``\n\n# Complexity\n- Time complexity: O(nlogn)\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```javascript []\n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findValueOfPartition = function(nums) {\n    // Javascript\'s default sorting converts the elements to strings first\n    // . For example, if nums was [3, 2, 10], simply calling nums.sort()\n    // would give you [10, 2, 3]\n    nums.sort((a,b) => a-b);\n\n    let minDiff = 1000000000;\n    for (let i = 0; i < nums.length; i++) {\n        if (i > 0)\n            minDiff = Math.min(minDiff, nums[i] - nums[i-1]);\n        if (i < nums.length-1)\n            minDiff = Math.min(minDiff, nums[i+1] - nums[i]);\n    }\n\n    return minDiff;\n};\n```
['JavaScript']