Maximum Product of Two Elements in an Array

Easy

Topics
ArraySorting

Given an array nums, choose two different indices i and j and return the maximum value of (nums[i]-1)*(nums[j]-1).

Example 1

Input:  nums = [3,4,5,2]
Output: 12

Example 2

Input:  nums = [1,5,4,5]
Output: 16

Constraints

  • 2 <= nums.length <= 500
  • 1 <= nums[i] <= 10^3
Run ⌘' · Submit ⌘⏎