- 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

# Maximum Sum of Products of Two Array in C++ Program

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,**

## Input

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

## Output

37

## Explanation

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

## Solution Approach

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.

## Example

**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; }

## Output

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
- Select maximum of sum of two columns in MySQL
- Program to find maximum sum of two non-overlapping sublists in Python
- Sum of the products of all possible Subsets in C++
- Maximize the sum of products of the degrees between any two vertices of the tree in C++
- Maximum Sum of Two Non-Overlapping Subarrays in C++
- Maximum sum of n consecutive elements of array in JavaScript
- Find Sum of pair from two arrays with maximum sum in C++
- Products of ranges in 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 average sum partition of an array in C++
- Program to find maximum sum of two sets where sums are equal in C++