Python solution in O(n) and O(1) extra memory
\ndef minDifference(self, nums: List[int]) -> int:\n   """\n        Runtime O(n) and O(1) extra memory. One pass the collect 4 smallest and largest elements. \n
```\ndef minDifference(self, nums: List[int]) -> int:\n   """\n        Runtime O(n) and O(1) extra memory. One pass the collect 4 smallest and largest elements. \n        Then 4 comparisons of endpoints.\n   """\n        n = len(nums)\n        if n <= 4:\n            return 0\n        min4 = nums[:4]\n        max4 = nums[:4]\n        for num in nums[4:]:\n            idx, num_other = max([(i, val) for i, val in enumerate(min4)], key=lambda x: x[1])\n            if num_other > num:\n                min4[idx] = num\n            idx, num_other = min([(i, val) for i, val in enumerate(max4)], key=lambda x: x[1])\n            if num_other < num:\n                max4[idx] = num\n        nums8 = sorted(min4) + sorted(max4)\n        minDiff = sys.maxsize\n        for i in range(4):\n            minDiff = min(minDiff, abs(nums8[i] - nums8[8 - 3 - 1 + i]))\n        return minDiff\n\t```
[]