Problem · Array

Make Array Distinct (Selling Shoes 🩰)

MediumAmazonFULLTIMEOA
See Amazon hiring insights

Howdy, dear user friends! This problem was identified as a duplicate of Get Minimal Cost. However, after serious consideration, I decided not to merge duplicates for now as both of them have received code submissions I will figure an approach to handle a situation like this in the future. Thank you for your understanding! Your dedication will be rewarded in ways you’ve been hoping for! 🩵

Problem Description Version No.2:

You are given two arrays size and cost of size n. The cost will be calculated for every increment.

Your task is to make the size array distinct by incrementing any of its elements and calculate the minimum cost to do so.

Function Description

Complete the function makeArrayDistinct in the editor.

makeArrayDistinct has the following parameters:

  1. 1. int[] size: an array of integers representing the sizes
  2. 2. int[] cost: an array of integers representing the costs

Returns

int: the minimum cost to make the size array distinct

Examples
01 · Example 1
size = [2, 3, 3, 2]
cost = [2, 4, 5, 1]
return = 7
You can make the size array distinct as {2, 4, 3, 5} with a minimum cost of 7.
02 · Example 2
size = [3, 7, 9, 7, 8]
cost = [5, 2, 5, 7, 5]
return = 6
You can make the size array distinct as {3, 10, 9, 7, 8} with a minimum cost of 6, which is 2 * (10 - 7) = 6.
More Amazon problems
drafts saved locally
public int makeArrayDistinct(int[] size, int[] cost) {
  // write your code here
}
size[2, 3, 3, 2]
cost[2, 4, 5, 1]
expected7
sign in to submit