Maximum Sum of Products of Two Arrays | Java program to calculate 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
import java . io . * ; import java . util . * ; public class GFG { static int maximumSOP ( int [ ] a , int [ ] b ) { int sop = 0 ; int n = a . length ; Arrays . sort ( a ) ; Arrays . sort ( b ) ; for ( int i = 0 ; i < n ; i ++ ) { sop += a [ i ] * b [ i ] ; } return sop ; } public static void main ( String args [ ] ) { int [ ] A = { 1 , 2 , 3 } ; int [ ] B = { 4 , 5 , 1 } ; System . out . println ( maximumSOP ( A , B ) ) ; } }