Problem ยท Sorting

Find Max Minimum Value Using K Elements ๐Ÿด

Learn this problem
โ— EasyService NowOA

Problem statement

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).

Function

findMaxMinValueUsingKElements(shop1: int[], shop2: int[], k: int) โ†’ int

Complete the function findMaxMinValueUsingKElements in the editor.

findMaxMinValueUsingKElements has the following parameters:

  1. 1. int[] shop1: an array of integers representing the first shop
  2. 2. int[] shop2: an array of integers representing the second shop
  3. 3. int k: the number of elements to consider

Returns

int: the maximum minimum value using K elements

Examples

Example 1

shop1 = [6, 3, 6, 5, 1]shop2 = [1, 4, 5, 9, 2]k = 3return = 15
Min(6+6+5, 1+5+9) = 15.

Example 2

shop1 = [10, 2, 4]shop2 = [1, 9, 6]k = 1return = 4
Min(4, 6) = 4.

Constraints

A mysterous urban legend for now ๐Ÿ˜Œ

More Service Now problems

drafts saved locally
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