Problem ยท Sorting
Find Max Minimum Value Using K Elements ๐ด
You have given 2 Arrays Shop1 of size N and shop2 of size N and an Integer K. You have to find the maximum, minimum value using K elements from both given arrays.
Calculate the minimum of the sum of K elements from both arrays, i.e., Min (a1+a2+...+ak, b1+b2+...+bk).
Complete the function findMaxMinValueUsingKElements in the editor.
findMaxMinValueUsingKElements has the following parameters:
- 1.
int[] shop1: an array of integers representing the first shop - 2.
int[] shop2: an array of integers representing the second shop - 3.
int k: the number of elements to consider
Returns
int: the maximum minimum value using K elements
Examples
01 ยท Example 1
shop1 = [6, 3, 6, 5, 1] shop2 = [1, 4, 5, 9, 2] k = 3 return = 15
Min(6+6+5, 1+5+9) = 15.
02 ยท Example 2
shop1 = [10, 2, 4] shop2 = [1, 9, 6] k = 1 return = 4
Min(4, 6) = 4.
Constraints
A mysterous urban legend for now ๐More Service Now problems
public int findMaxMinValueUsingKElements(int[] shop1, int[] shop2, int k) {
// write your code here
}
shop1[6, 3, 6, 5, 1]
shop2[1, 4, 5, 9, 2]
k3
expected15
checking account