Created
October 23, 2021 16:30
-
-
Save Shivani13121007/a1b152ce706e1cfe3d9887a5c094d032 to your computer and use it in GitHub Desktop.
Maximum Product of Two Elements in an Array
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 maxProduct(int[] nums) { | |
int n = nums.length; | |
Arrays.sort(nums); | |
int res = (nums[n-1] -1) * (nums[n-2] -1); | |
return res; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment