LeetCode solutions

2042. Maximum Product Difference Between Two Pairs

My accepted Python solution to LeetCode problem 2042, Maximum Product Difference Between Two Pairs, running in 140ms.

  • Difficulty: Easy
  • Python
  • Runtime 140ms
  • Memory 18.9MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 140ms, memory 18.9MB, accepted 2025-12-31.

python
class Solution:
    def maxProductDifference(self, nums: List[int]) -> int:
        nums.sort()
        return nums[-1] * nums[-2] - nums[0] * nums[1]

Source