Geeksforgeeks

X

DAYS

:

HOUR

:

MINS

:

SEC

Error

Copied to Clipboard

Given two arrays **A** and **B** of positive integers of size **N** and **M** where **N >= M**, the task is to maximize the dot product by inserting zeros in the second array but you cannot disturb the order of elements.

Dot Product of array A and B of size N is **A[0]*B[0] + A[1]*B[1]+....A[N]*B[N].**

**Example 1:**

**Input**: N = 5, A[] = {2, 3, 1, 7, 8}
M = 3, B[] = {3, 6, 7}
**Output:** 107
**Explanation**: We get maximum dot product
after inserting 0 at first and third
positions in second array.
Maximum Dot Product : = A[i] * B[j]
2*0 + 3*3 + 1*0 + 7*6 + 8*7 = 107

**Example 2:**

**Input**: N = 3, A[] = {1, 2, 3}
M = 1, B[] = {4}
**Output:** 12
**Explanation**: We get maximum dot product
after inserting 0 at first and second
positions in second array.
Maximum Dot Product : = A[i] * B[j]
1*0 + 2*0 + 3*4 = 12

**Your Task: **

You don't need to read input or print anything. Complete the function ** maxDotProduct() **which takes

1 ≤ M ≤N ≤ 10

1 ≤ A[i], B[i] ≤ 10

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Maximize Dot Product

...

Here is some troubleshooting advice:

- Reset the IDE using the second button on the top right corner.
- Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
- Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
- You can access the hints to get an idea about what is expected of you as well as the final solution code.
- You can view the solutions submitted by other users from the submission tab.

Here is some troubleshooting advice for contest problems

- Make sure you are not using ad-blockers.
- Disable browser extensions.
- We recommend using latest version of your browser for best experience.
- Avoid using static/global variables in coding problems as your code is tested against multiple test cases and these tend to retain their previous values.
- Passing the Sample/Custom Test cases in coding problems does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.