- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this problem, we are given two arrays arr1[] and arr2[] of size n. Our task is to create a program to find the maximum Sum of Products of Two Array.

**Problem Description** − We need to find the maximum sum of products of two arrays. We need to find the maximum sum of the product of one element from arr1 and other elements from arr2.

**Let’s take an example to understand the problem,**

arr1[] = {3, 5, 6} arr2[] = {1, 4, 2}

37

Maximum sum of products: 6*4 + 5*2 + 3*1 = 24 + 10 + 3 = 37

A simple solution to the problem is by finding all pairs of elements from arr1 and arr2. And then return the maximum sum.

An efficient solution to the problem is by multiplying the largest values from both arrays together. An easy way to do this is by sorting the array in descending order. Then multiply all elements for both arrays from index 0 to n and return their sum.

**Program to illustrate the working of our solution,**

#include<bits/stdc++.h> using namespace std; int calcMaxSumOfProd(int arr1[], int arr2[], int n){ int maxSum = 0; sort(arr1, arr1 + n, greater<int>()); sort(arr2, arr2 + n, greater<int>()); for (int i = 0; i < n; i++) maxSum += (arr1[i] * arr2[i]); return maxSum; } int main() { int arr1[] = { 3, 5, 6 }; int arr2[] = { 1, 4, 2 }; int n = sizeof(arr1)/sizeof(arr1[0]); cout<<"The maximum Sum of Products of two arrays is "<<calcMaxSumOfProd(arr1, arr2, n); return 0; }

The maximum Sum of Products of two arrays is 37

- Related Questions & Answers
- Maximum Sum of Products of Two Arrays in C++
- Maximum Possible Sum of Products in JavaScript
- Maximum products of two integers in linear time in JavaScript
- Sum of the products of all possible Subsets in C++
- Maximum Sum of Two Non-Overlapping Subarrays in C++
- Maximize the sum of products of the degrees between any two vertices of the tree in C++
- Products of ranges in an array in C
- Select maximum of sum of two columns in MySQL
- Maximum average sum partition of an array in C++
- Maximum OR sum of sub-arrays of two different arrays in C++
- Maximum sum of smallest and second smallest in an array in C++ Program
- Maximum possible difference of two subsets of an array in C++
- Program to find maximum sum of two sets where sums are equal in C++
- Maximum sum two non-overlapping subarrays of given size in C++
- Maximum XOR of Two Numbers in an Array in C++

Advertisements