1913. Maximum Product Difference Between Two Pairs
```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
*/
```
Last updated