O(n) || Most efficient || 99.3 || Without Sorting
Approach\r\n- Without sorting\r\n- Just keeping track of min and max\r\n- Iterating through whole loop\r\n- Atlast applying those variable in formula\r\n\r\n# C
# Approach\r\n- Without sorting\r\n- Just keeping track of min and max\r\n- Iterating through whole loop\r\n- Atlast applying those variable in formula\r\n\r\n# Complexity\r\n- Time complexity:\r\nO(n)\r\n\r\n- Space complexity:\r\nO(n)\r\n\r\n# Code\r\n```\r\nclass Solution:\r\n    def maxProductDifference(self, nums: List[int]) -> int:\r\n        min1=min2=10000000\r\n        max1=max2=-1\r\n\r\n        for i in nums : \r\n            # Min \r\n            if i<min1 : \r\n                min2=min1\r\n                min1=i\r\n            elif min1<=i<=min2 :\r\n                min2=i\r\n            # Max\r\n            if  i>=max1 : \r\n                max2=max1\r\n                max1=i\r\n            elif max2<=i<=max1 :\r\n                max2 = i\r\n        return max2*max1-min2*min1\r\n```
['Python3']