1464. Maximum Product of Two Elements in an Array

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1464

class Solution:
    def maxProduct(self, nums: List[int]) -> int:
        a = b = 0
        for v in nums:
            if v > a:
                a, b = v, a
            elif v > b:
                b = v
        return (a - 1) * (b - 1)