"Find maximum product of two integers in an array" Code Answer's
You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "Find maximum product of two integers in an array" answered properly. Developers are finding an appropriate answer about Find maximum product of two integers in an array related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like Find maximum product of two integers in an array. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on Find maximum product of two integers in an array.
Find maximum product of two integers in an array
def findMaximumProduct(A):
# to store the maximum and second maximum element in a list
max1 = A[0]
max2 = -sys.maxsize
# to store the minimum and second minimum element in a list
min1 = A[0]
min2 = sys.maxsize
for i in range(1, len(A)):
# if the current element is more than the maximum element,
# update the maximum and second maximum element
if A[i] > max1:
max2 = max1
max1 = A[i]
# if the current element is less than the maximum but greater than the
# second maximum element, update the second maximum element
elif A[i] > max2:
max2 = A[i]
# if the current element is more than the minimum element,
# update the minimum and the second minimum
if A[i] < min1:
min2 = min1
min1 = A[i]
# if the current element is less than the minimum but greater than the
# second minimum element, update the second minimum element
elif A[i] < min2:
min2 = A[i]
# otherwise, ignore the element
# choose the maximum of
# 1. Product of the maximum and second maximum element or
# 2. Product of the minimum and second minimum element
if max1 * max2 > min1 * min2:
print("Pair is", (max1, max2))
else:
print("Pair is", (min1, min2))
All those coders who are working on the Whatever based application and are stuck on Find maximum product of two integers in an array can get a collection of related answers to their query. Programmers need to enter their query on Find maximum product of two integers in an array related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about Find maximum product of two integers in an array for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of Find maximum product of two integers in an array while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "Find maximum product of two integers in an array". Visit this developer's friendly online web community, CodeProZone, and get your queries like Find maximum product of two integers in an array resolved professionally and stay updated to the latest Whatever updates.