Problem · Array

Find Minimum Pen Drive Capacity

Learn this problem
MediumAmazonOA
See Amazon hiring insights

Problem statement

Need to efficiently distribute a collection of computer games among k different children. Each game is characterized by its size, denoted by gameSize[i] for 1 ≤ i ≤ n.

To facilitate the distribution process, the coordinator opts to utilize pen drives, ordering k pen drives with identical storage capacities. Each child can receive a maximum of 2 games, and every child must receive at least one game, also no game should be left unassigned.

Considering the impracticality of transferring large game files over the internet, the strategy involves determining the minimum storage capacity required for the pen drives. A pen drive can only store games if the sum of their sizes does not exceed the pen drive's storage capacity.

What is the minimum storage capacity of pen drives that you must order to be able to give these games to the children?

Function

findMinimumPenDriveCapacity(gameSize: int[], k: int) → int

Complete the function findMinimumPenDriveCapacity in the editor.

findMinimumPenDriveCapacity has the following parameters:

  1. int[] gameSize: an array of integers representing the sizes of the games
  2. int k: the number of children

Returns

int: the minimum storage capacity of pen drives required

Examples

Example 1

gameSize = [9, 2, 4, 6]k = 3return = 9

We note that we will need pen drives of the size of at least 9 units to store the first game. This also turns out to be the minimum size of pen drives that should be ordered to give the games to these children.

We can use the first pen drive to store the game of size 9, the 2nd one to store the second and third games, and the 3rd pen drive to store the fourth game. Hence, the minimum capacity of pen drives required is 9 units.

Constraints

🐻‍❄️

More Amazon problems

drafts saved locally
public int findMinimumPenDriveCapacity(int[] gameSize, int k) {
  // write your code here
}
gameSize[9, 2, 4, 6]
k3
expected9
checking account