Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shivani13121007/a1b152ce706e1cfe3d9887a5c094d032 to your computer and use it in GitHub Desktop.
Save Shivani13121007/a1b152ce706e1cfe3d9887a5c094d032 to your computer and use it in GitHub Desktop.
Maximum Product of Two Elements in an Array
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