Maximum Product of Two Elements
Choose two different positions i and j of nums and compute (nums[i] - 1) * (nums[j] - 1). Return the largest value this can have.
Example 1
nums [3,4,5,2]
returns 12
(5-1) * (4-1) = 12.
Example 2
nums [1,5,4,5]
returns 16
(5-1) * (5-1) = 16.
Constraints
2 <= len(nums) <= 301 <= nums[i] <= 50
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Sorting and searching problems
- Median of the ListBeginner
- Names in OrderBeginner
- Shortest Words FirstBeginner
- Sort by Last DigitBeginner
- Strictly Increasing CheckBeginner
- Top Three ValuesBeginner
- Where It LandsBeginner
- Widest Gap After SortingBeginner