Leetcode 1574 Solution

This article provides solution to leetcode question 1574 (maximum-product-of-two-elements-in-an-array)

https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array

Solution

class Solution:
    def maxProduct(self, nums: List[int]) -> int:
        max1 = 0
        max2 = 0

        for num in nums:
            if num >= max1:
                max2 = max1
                max1 = num
            elif num >= max2:
                max2 = num
        return (max1 - 1) * (max2 - 1)