[Python] O(N) Time, O(1) Space, beats 100 % without sorting
We only need to find the max 4 and min 4 elements in nums, and It could be done by O(n) time without sorting (O(nlogn)).\n\nclass Solution:\n    def minDifferen
We only need to find the max 4 and min 4 elements in nums, and It could be done by O(n) time without sorting (O(nlogn)).\n```\nclass Solution:\n    def minDifference(self, nums: List[int]) -> int:\n        if len(nums) < 5:\n            return 0\n        \n        maxV, minV = [-float(\'inf\')] * 4, [float(\'inf\')] * 4\n        for n in nums:\n            if n > maxV[0]:\n                maxV[0] = n\n                for i in range(0, 3):\n                    if maxV[i] > maxV[i + 1]:\n                        maxV[i], maxV[i + 1] = maxV[i + 1], maxV[i]     \n            if n < minV[0]:\n                minV[0] = n\n                for i in range(0, 3):\n                    if minV[i] < minV[i + 1]:\n                        minV[i], minV[i + 1] = minV[i + 1], minV[i]\n        \n        return min(maxV[i] - minV[3 - i] for i in range(4))    \n```
['Python', 'Python3']