Find Max Minimum Value Using K Elements 🐴
Updated
Problem statement
You are given two arrays, shop1 and shop2, both of size N, and an integer K. You have to find the maximum possible minimum value using K elements from both arrays.
Choose exactly K different indices i1, i2, ..., iK. The same indices are used in both arrays. The value of the choice is the smaller of the two sums:
Min(shop1[i1] + ... + shop1[iK], shop2[i1] + ... + shop2[iK])
Return the largest value over all possible choices.
For example, if shop1 = [6, 3, 6, 5, 1], shop2 = [1, 4, 5, 9, 2] and K = 3, choosing indices 0, 2, 3 gives Min(6 + 6 + 5, 1 + 5 + 9) = Min(17, 15) = 15, and no other choice does better.
Complete the function findMaxMinValueUsingKElements in the editor.
findMaxMinValueUsingKElements has the following parameters:
int[] shop1: an array of integers representing the first shopint[] shop2: an array of integers representing the second shopint k: the number of indices to choose
The function returns an int: the maximum possible value of the smaller sum.
Function
findMaxMinValueUsingKElements(shop1: int[], shop2: int[], k: int) → intExamples
Example 1
shop1 = [6, 3, 6, 5, 1]shop2 = [1, 4, 5, 9, 2]k = 3return = 15Min(6+6+5, 1+5+9) = 15.
Example 2
shop1 = [10, 2, 4]shop2 = [1, 9, 6]k = 1return = 4Min(4, 6) = 4.
Constraints
1 ≤ N ≤ 50shop1.length == shop2.length == N1 ≤ k ≤ N1 ≤ shop1[i], shop2[i] ≤ 50
More ServiceNow interview questions
Similar questions at other companies
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Maximum Apples That Fit in a BoxVirtu Financial · OAVirtu Financial interview questions
- Server ManagementRippling · OARippling interview questions
- Maximum Three-Server Difficulty ScoreVisa · OAVisa interview questions
- Economical TripAccenture · OAAccenture interview questions
- Minimum Pile Reduction StepsAmerican Express · OAAmerican Express interview questions
- Find Maximum Number of Subjects Passed (AS Intern, but it may apply to other interns) 🍋Amazon · OA
- Maximum Production Within PowerZomato / Eternal · OAZomato / Eternal interview questions
- Can Every Package Fit in a BoxIMC Trading · OAIMC Trading interview questions
- Compute Walking DistanceTikTok · OATikTok interview questions