Problem · Dynamic Programming

Minimum Cost to Select People for Skill Quotas

HardVisaFULLTIMEOA

There are n people. Person i has hiring cost costs[i] and may have Skill 1, Skill 2, both skills, or neither skill.

For every K from 1 to n, compute the minimum total hiring cost needed so that the selected subset contains at least K people with Skill 1 and at least K people with Skill 2. A person who has both skills contributes to both counts.

Return an array ans of length n where ans[K - 1] is the minimum cost for that quota, or -1 if it is impossible.

Function Description

Complete the function minimumCostForSkillQuotas in the editor below.

minimumCostForSkillQuotas has the following parameters:

  1. int[] costs: hiring costs for each person
  2. int[] skill1: 1 if the person has Skill 1, else 0
  3. int[] skill2: 1 if the person has Skill 2, else 0

Returns

long[]: the minimum cost for every quota size K = 1..n.

Examples
01 · Example 1
costs = [3, 5, 2, 6]
skill1 = [1, 0, 1, 0]
skill2 = [0, 1, 1, 0]
return = [2, 10, -1, -1]

For K = 1, hiring only the third person is enough because that person has both skills. For K = 2, the cheapest feasible subset costs 10. Larger quotas are impossible.

02 · Example 2
costs = [4, 7, 3]
skill1 = [1, 0, 1]
skill2 = [0, 1, 1]
return = [3, 14, -1]

For K = 1, hiring the third person alone is sufficient. For K = 2, all three people must be hired.

More Visa problems
drafts saved locally
public long[] minimumCostForSkillQuotas(int[] costs, int[] skill1, int[] skill2) {
    // write your code here
}
costs[3, 5, 2, 6]
skill1[1, 0, 1, 0]
skill2[0, 1, 1, 0]
expected[2, 10, -1, -1]
sign in to submit