package leetcode;

/**
 * https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array/
 */
public class Problem1464 {
    public int maxProduct(int[] nums) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1464 prob = new Problem1464();
        System.out.println(prob.maxProduct(new int[]{3,4,5,2})); // 12
        System.out.println(prob.maxProduct(new int[]{1,5,4,5})); // 16
        System.out.println(prob.maxProduct(new int[]{3,7})); // 12
    }
}

package leetcode;

/**
 * https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array/
 */
public class Problem1464 {
    public int maxProduct(int[] nums) {
        int max1 = 0;
        int max2 = 0;
        for (int num : nums) {
            if (num > max1) {
                max2 = max1;
                max1 = num;
            } else if (num > max2) {
                max2 = num;
            }
        }
        return (max1 - 1) * (max2 - 1);
    }
}

Solve problem 1464