Maximum Sum of Products of Two Arrays | Function that calculates maximum sum of products of two arrays ; Variable to store the sum of products of array elements ; length of the arrays ; Sorting both the arrays ; Traversing both the arrays and calculating sum of product ; Driver code
def maximumSOP ( a , b ) : NEW_LINE INDENT sop = 0 NEW_LINE n = len ( a ) NEW_LINE a . sort ( ) NEW_LINE b . sort ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT sop += a [ i ] * b [ i ] NEW_LINE DEDENT return sop NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT A = [ 1 , 2 , 3 ] NEW_LINE B = [ 4 , 5 , 1 ] NEW_LINE print ( maximumSOP ( A , B ) ) NEW_LINE DEDENT