Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6380 |

@mb1973 | 5704 |

@Quandray | 5245 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 5046 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3523 |

@mantu_singh | 3514 |

@sushant_a | 3459 |

Complete Leaderboard | |

Handle | Score |

@cfwong8 | 1156 |

@gurshehzadsingh | 676 |

@nithinreddy3210 | 642 |

@jha8768 | 577 |

@Run_for_life | 574 |

@divyagupta221100 | 557 |

@AkashLahoty | 553 |

@aayushdesai01 | 526 |

@riyakumaribkj | 526 |

@2017akku | 521 |

@amansinha74458 | 503 |

Complete Leaderboard |

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

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

...