Simple O(n) time solution, with explanation & code in python
The maximum product difference of an array can be found by subtracting product of the 2 largest numbers of the array from the product of the 2 smallest.\nIn the
The maximum product difference of an array can be found by subtracting product of the 2 largest numbers of the array from the product of the 2 smallest.\nIn the following code, the `max1` and `max2` variables are for 2 largest number from the input list while `min1` and `min2` are for the 2 smallest. More specifically `max1` will be the largest number and `max2` will be the 2nd largest while `min1` will be the smallest and `min2` will be the 2nd smallest.\n\nFirst we set max1 and max2 to the smallest possible number  (negative infinity) and min1 and min2 to the largest possible number (infinity) (which is standard practice for finding largest/smallest value from a collection of values.\n\nNext we iterate over the input array and for each number we do two things:\n1) check if its larger than max1; if it is then we move the current max1 value down to max2 and set max1 to the current number. If the number isnt larger than max1 then we check if its larger than max2 (but still not larger than max1 ofcourse), and if it is we set max2 to that number\n\n2) check if its smaller than min1; if it is then we move the current min1 value down to min2 and set min1 to the current number. If the number isnt smaller than min1 then we check if its smaller than min2 (but still not smaller than min1 ofcourse),and if it is we set min2 to that number\n\nIn the end (after the loop) we just return the product of max1 and max2 minus the product of min1 and min2.\n\n```\nclass Solution:\n    def maxProductDifference(self, nums: List[int]) -> int:\n        # max1 > max 2\n        # min1 < min2\n        \n        max1 = max2 = float("-inf")\n        min1 = min2 = float("inf")\n        \n        for num in nums:\n            if num > max1:\n                max2 = max1\n                max1 = num\n            elif num > max2:\n                max2 = num\n                \n            if num < min1:\n                min2 = min1\n                min1 = num\n            elif num < min2:\n                min2 = num\n                \n        return (max1 * max2) - (min1 * min2)\n```
['Python']