FastPrepFastPrep
Problem Brief

Make Array Distinct (Selling Shoes 🩰)

FULLTIMEOA
See Amazon online assessment and 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

1Example 1

Input
size = [2, 3, 3, 2], cost = [2, 4, 5, 1]
Output
7
Explanation
You can make the size array distinct as {2, 4, 3, 5} with a minimum cost of 7.

2Example 2

Input
size = [3, 7, 9, 7, 8], cost = [5, 2, 5, 7, 5]
Output
6
Explanation
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.
public int makeArrayDistinct(int[] size, int[] cost) {
  // write your code here
}
Input

size

[2, 3, 3, 2]

cost

[2, 4, 5, 1]

Output

7

Sign in to submit your solution.