Showing:
Handle Score
@Ibrahim Nash 6420
@mb1973 5704
@Quandray 5245
@akhayrutdinov 5111
@saiujwal13083 5046
@sanjay05 3762
@kirtidee18 3673
@marius_valentin_dragoi 3523
@mantu_singh 3514
@sushant_a 3459
Maximize Dot Product
Easy Accuracy: 35.08% Submissions: 769 Points: 2

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

You don't need to read input or print anything. Complete the function maxDotProduct() which takes N, M, array A and B as input parameters and returns the maximum value.

Expected Time Complexity: O(N*M)
Expected Auxiliary Space: O(N*M)

Constraints:
1 ≤ M ≤N ≤ 103

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