From 52d7d5a17480b47427fc5998e120e80f88d47cac Mon Sep 17 00:00:00 2001 From: Sapan Desai <35861214+sapan17@users.noreply.github.com> Date: Sat, 31 Oct 2020 11:00:21 +0530 Subject: [PATCH] Create Maximum Product of Two Elements in an Array.py This program helps to find two elements which help to form the maximum product. --- Maximum Product of Two Elements in an Array.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Maximum Product of Two Elements in an Array.py diff --git a/Maximum Product of Two Elements in an Array.py b/Maximum Product of Two Elements in an Array.py new file mode 100644 index 0000000..dc40ade --- /dev/null +++ b/Maximum Product of Two Elements in an Array.py @@ -0,0 +1,11 @@ +class Solution(object): + def maxProduct(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + z = max(nums) - 1 + nums.sort() + n = len(nums) + y = nums[n-2] -1 + return z*y