> For the complete documentation index, see [llms.txt](https://timmybeeflin.gitbook.io/cracking-leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://timmybeeflin.gitbook.io/cracking-leetcode/o-n-to-find-top2-min-or-max-number/1913.-maximum-product-difference-between-two-pairs.md).

# 1913. Maximum Product Difference Between Two Pairs

````java
```java
class Solution {
    public int maxProductDifference(int[] nums) {
        int max = 0;
        int secondMax = max;
        int min = Integer.MAX_VALUE;
        int secondMin = min;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] > max) { 
                secondMax = max; // 6
                max = nums[i]; // m 7
            } else if (nums[i] > secondMax) {
                secondMax = nums[i];
            }
            if (nums[i] < min) {
                secondMin = min; // 5
                min = nums[i]; // min = 2
            } else if (nums[i] < secondMin) {
                secondMin = nums[i]; // 4
            }
        }
        return max*secondMax - min*secondMin;
    }
}

/**
(a*b) max
(c*d) min

 */
```
````
