Geeksforgeeks

Error

×

Leaderboard

Showing:

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

@Ibrahim Nash | 6379 |

@blackshadows | 6329 |

@mb1973 | 5358 |

@Quandray | 5231 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3357 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@ritiksethi21 | 1050 |

@aroranayan999 | 807 |

@RizulBansal | 685 |

@ashishtrehan002 | 538 |

@hemantgarg923 | 528 |

@simrangoyal | 526 |

@ronaldo77 | 520 |

@anishrajan | 505 |

@thanosagain | 505 |

@ssparteek470 | 495 |

@rahul2312 | 491 |

Complete Leaderboard |

You are given two arrays,** A** and **B**, of equal size **N**. The task is to find the minimum value of **A[0] * B[0] + A[1] * B[1] +…+ A[N-1] * B[N-1],** where shuffling of elements of arrays **A** and **B** is allowed.

**Example 1:**

**Input:**
N = 3
A[] = {3, 1, 1}
B[] = {6, 5, 4}
**Output:**
23
**Explanation:**
1*6+1*5+3*4 = 6+5+12
= 23 is the minimum sum

**Example 2:**

**Input:**
N = 5
A[] = {6, 1, 9, 5, 4}
B[] = {3, 4, 8, 2, 4}
**Output:**
80
**Explanation:**
2*9+3*6+4*5+4*4+8*1
=18+18+20+16+8
= 80 is the minimum sum

**Your Task: **

You don't need to read input or print anything. Your task is to complete the function **minValue()** which takes the arrays **A[]**, **B[]** and its size **N**** **as inputs and returns the minimum sum.

**Expected Time Complexity:** O(N. log(N))

**Expected Auxiliary Space:** O(1)

**Constraints:**

1 ≤ N ≤ 10^{5}

1 ≤ A[] ≤ 10^{6}

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?

Yes
Minimize the sum of product

...