Maximum Product of Two Elements in an Array Problem

Maximum Product of Two Elements in an Array Problem — ExecCode Easy DSA Practice

Solve the Maximum Product of Two Elements in an Array problem on ExecCode. Free online easy DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given the array of integers nums, you will choose two different indices i and j of that array. Your task is to compute the required answer and return the maximum value of (nums[i]-1)(nums[j]-1).

Examples

Input {"nums": [3, 4, 5, 2]}; Output 12. Input {"nums": [1, 5, 4, 5]}; Output 16

Constraints

2 <= nums.length <= 500 1 <= nums[i] <= 10^3

Practice Maximum Product of Two Elements in an Array free on ExecCode. Browse DSA problems, topic map, and placement guides.