One of the products listed on Amazon Ecommerce is available in n sizes as indicated in the array size. The category manager recognizes that some of the sizes are repetitive and do not provide a good user experience. To make the best use of inventory, the product should be available in distinct sizes. The size of the i-th product, size[i], can be increased by one unit for an amount in the cost array, cost[i].
Given the arrays size and cost for the product, find the minimal total cost in order to make all the sizes distinct.
Complete the function minimalCostToIncreasePackageSize in the editor.
minimalCostToIncreasePackageSize has the following parameters:
- 1.
int size[n]: an array of integers representing the sizes - 2.
int cost[n]: an array of integers representing the cost to increase each size
Returns
int: the minimal total cost to make all the sizes distinct
size = [2, 3, 2, 2] cost = [2, 4, 5, 1] return = 7
size[1] to 5, which costs cost[1] * (5 - size[1]) = 8, and size[3] to 4, which costs cost[3] * (4 - size[3]) = 2. Therefore, the total cost is 8 + 2 = 10. However, 7 is the minimum cost required to make all sizes distinct.🐹- Count Promotional PeriodsOA · Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Find Minimum CostOA · Seen Jun 2026
- Get Smallest Base SegmentOA · Seen Jun 2026
- Select Least Resource TasksOA · Seen Jun 2026
- Product Category Group SizesPHONE SCREEN · Seen May 2026
- Count Connected ComponentsPHONE SCREEN · Seen May 2026
public int minimalCostToIncreasePackageSize(int[] size, int[] cost) {
// write your code here
}