educative.io

Why do we need min?

We need to find two max integers and that’s it

def find_max_prod(lst):
"""
Finds the pair having maximum product in a given list
:param lst: A list of integers
:return: A pair of integer
"""

# Write your code here!
max1, max2 = lst[0], lst[0]
for num in lst:
    if num > max1:
        max2 = max1
        max1 = num
    elif num > max2:
        max2 = num
return max1, max2

Course: https://www.educative.io/collection/10370001/5550095527313408
Lesson: https://www.educative.io/collection/page/10370001/5550095527313408/5568738088714240

Hello Suleiman,

Since we are working with a list of integers, we can have negative numbers as well. This means that in some cases, the two lowest (negative) integers can have the highest product. For example, the integers with the highest product in the second list in the main function are -3 and -5 which also are the lowest integers.
So our function compares the product of the highest and second highest integers, and the product of the lowest and second lowest integer.