Find the maximum value of over all pairs of distinct elements in an array.
Given an array of positive integers, choose two different elements and . Your task is to maximize the value of
Return the largest possible product.
Since subtracting 1 from each number preserves ordering, the best pair will come from the two largest values in the array.
nums of length at least 2.Example 1
Input
nums = [3,4,5,2]
Output
12
Explanation
The two largest numbers are 5 and 4. The product is (5 - 1) * (4 - 1) = 12.
Example 2
Input
nums = [1,5,4,5]
Output
16
Explanation
The two largest numbers are 5 and 5. The product is (5 - 1) * (5 - 1) = 16.
Example 3
Input
nums = [3,7]
Output
12
Explanation
Only one pair exists: (3 - 1) * (7 - 1) = 12.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.