Back to all solutions
#1464 - Maximum Product of Two Elements in an Array
Problem Description
Given the array of integers nums, you will choose two different indices i and j of that array. Return the maximum value of (nums[i]-1)*(nums[j]-1).
Solution
/**
* @param {number[]} nums
* @return {number}
*/
var maxProduct = function(nums) {
const [a, b] = nums.sort((a, b) => b - a);
return (a - 1) * (b - 1);
};