Skip to content

Commit ef24936

Browse files
authoredDec 18, 2023
Create 913) Maximum product difference between two pairs.cpp
1 parent d6a946f commit ef24936

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
public:
3+
int maxProductDifference(vector<int>& nums) {
4+
int max1,max2= INT_MIN;
5+
int min1,min2=INT_MAX ;
6+
for(int num : nums) {
7+
if(num>max1) {
8+
max2=max1;
9+
max1=num;
10+
}
11+
else if(num>max2) {
12+
max2=num;
13+
}
14+
if(num<min1) {
15+
min2=min1;
16+
min1=num;
17+
}
18+
else if(num<min2) {
19+
min2=num;
20+
}
21+
}
22+
return max((max1*max2)-(min1*min2),(max1*max2)-(min1*min2));
23+
}
24+
};

0 commit comments

Comments
 (0)