LeetCode 1913, Easy. Topics: Array, Sorting, Quicksort. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 17 parametrized pytest cases, and a playground notebook:
Problem
The product difference between two pairs (a, b) and (c, d) is defined as (a * b) - (c * d).
- For example, the product difference between
(5, 6) and (2, 7) is (5 * 6) - (2 * 7) = 16.
Given an integer array nums, choose four distinct indices w, x, y, and z such that the product difference between pairs (nums[w], nums[x]) and (nums[y], nums[z]) is maximized.
Return the maximum such product difference.
Examples
Constraints
- 4 <= nums.length <= 10^4
- 1 <= nums[i] <= 10^4
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
NeetCode All. Last modified on September 7, 2026