Created
October 23, 2021 16:22
-
-
Save Shivani13121007/12da48354342c50e1680105dbd0e4eb2 to your computer and use it in GitHub Desktop.
Maximum Product Difference Between Two Pairs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public int maxProductDifference(int[] nums) { | |
int n = nums.length; | |
Arrays.sort(nums); | |
int a = nums[0]; | |
int b = nums[1]; | |
int c = nums[n-1]; | |
int d = nums[n-2]; | |
int res = Math.abs((a*b) - (c*d)); | |
return res; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment