K-Capable Model Selection
Learn this problemProblem statement
You are given n machine learning models.
For each model:
cost[i]is the cost of theith model.featureAvailability[i]is a binary string of length2describing which features the model supports.
The availability string has the following meaning:
"00": supports neither Feature A nor Feature B."01": supports only Feature B."10": supports only Feature A."11": supports both Feature A and Feature B.
A selected set of models is k-capable if at least k selected models support Feature A and at least k selected models support Feature B. A model with availability "11" contributes to both counts.
For every integer k from 1 to n, determine the minimum total cost required to select a k-capable set of models. If it is impossible for a value of k, return -1 for that value.
Function
minimumKCapableCosts(cost: int[], featureAvailability: String[]) → long[]Complete the function minimumKCapableCosts.
int[] cost: the model costs.String[] featureAvailability: the feature availability strings.
Returns
long[]: an array of length n, where the k - 1 index stores the minimum total cost for k.
Examples
Example 1
cost = [3, 2, 5]featureAvailability = ["10", "01", "11"]return = [5, 10, -1]For k = 1, selecting the third model costs 5 and covers both features. For k = 2, all three models are required, for total cost 10. For k = 3, there are not enough models supporting either feature, so the answer is -1.
Constraints
cost.length == featureAvailability.length- Each
featureAvailability[i]is one of"00","01","10", or"11".