Beats 83.48% Easy solutions
Intuition\r\n Describe your first thoughts on how to solve this problem. \r\n\r\n# Approach\r\n Describe your approach to solving the problem. \r\n\r\n# Complex
# Intuition\r\n<!-- Describe your first thoughts on how to solve this problem. -->\r\n\r\n# Approach\r\n<!-- Describe your approach to solving the problem. -->\r\n\r\n# Complexity\r\n- Time complexity:\r\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\r\n\r\n- Space complexity:\r\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\r\n\r\n# Code\r\n```\r\nclass Solution:\r\n    def maxProductDifference(self, nums: List[int]) -> int:\r\n        # sort_num = sorted(nums)\r\n        # first = sort_num[0] * sort_num[1]\r\n        # last = sort_num[-1] * sort_num[-2]\r\n        # return last - first\r\n\r\n        small = float(inf)\r\n        smallest = float(inf)\r\n        big = float(-inf)\r\n        biggest = float(-inf)\r\n        for i in nums:\r\n            if i > biggest:\r\n                big = biggest\r\n                biggest = i\r\n                \r\n            else:\r\n                big = max(big, i)\r\n            \r\n            if i < smallest:\r\n                small = smallest\r\n                smallest = i\r\n            else:\r\n                small = min(small, i)\r\n        \r\n        return ((biggest * big) - (small * smallest))\r\n\r\n\r\n\r\n```
['Python3']