Python 3 -> Using heap
Suggestions to make it better are always welcomed.\n\n\nclass Solution:\n    def maxProduct(self, nums: List[int]) -> int:\n        # approach 1: find 2 max num
**Suggestions to make it better are always welcomed.**\n\n```\nclass Solution:\n    def maxProduct(self, nums: List[int]) -> int:\n        # approach 1: find 2 max numbers in 2 loops. T = O(n). S = O(1)\n\t\t# approach 2: sort and then get the last 2 max elements. T = O(n lg n). S = O(1)\n\t\t# approach 3: build min heap of size 2. T = O(n lg n). S = O(1)\n\t\t# python gives only min heap feature. heaq.heappush(list, item). heapq.heappop(list)\n        \n        heap = [-1]\n        for num in nums:\n            if num > heap[0]:\n                if len(heap) == 2:\n                    heapq.heappop(heap)\n                heapq.heappush(heap, num)\n                \n        return (heap[0]-1) * (heap[1]-1)\n```\n**I hope that you\'ve found this useful.\nIn that case, please upvote. It only motivates me to write more such posts\uD83D\uDE03**
['Heap (Priority Queue)', 'Python3']