Maximize product of array by replacing array elements with its sum or product with element from another array | Function to find the largest product of array A [ ] ; Base Case ; Store all the elements of the array A [ ] ; Sort the Array B [ ] ; Traverse the array B [ ] ; Pop minimum element ; Check which operation is producing maximum element ; Insert resultant element into the priority queue ; Evaluate the product of the elements of A [ ] ; Return the maximum product ; Given arrays ; Function Call
def largeProduct ( A , B , N ) : NEW_LINE INDENT if ( N == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT pq = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT pq . append ( A [ i ] ) NEW_LINE DEDENT B . sort ( ) NEW_LINE pq . sort ( reverse = True ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT minn = pq . pop ( ) NEW_LINE maximized_element = max ( minn * B [ i ] , minn + B [ i ] ) NEW_LINE pq . append ( maximized_element ) NEW_LINE pq . sort ( reverse = True ) NEW_LINE DEDENT max_product = 1 NEW_LINE while ( len ( pq ) > 0 ) : NEW_LINE INDENT max_product *= pq . pop ( ) ; NEW_LINE DEDENT return max_product NEW_LINE DEDENT A = [ 1 , 1 , 10 ] NEW_LINE B = [ 1 , 1 , 1 ] NEW_LINE N = 3 NEW_LINE print ( largeProduct ( A , B , N ) ) NEW_LINE