Minimize Cost for Feature-Capable Models
Company: Walmart
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Take-home Project
Quick Answer: This question evaluates algorithmic problem-solving and combinatorial optimization skills related to selecting cost-minimal subsets that satisfy dual feature-coverage constraints.
Constraints
- 0 <= n == len(cost) == len(featureAvailability) <= 2 * 10^5
- 1 <= cost[i] <= 10^9
- featureAvailability[i] is one of "00", "01", "10", "11"
- If n = 0, return an empty list
Examples
Input: ([3, 2, 7, 5, 1], ["10", "01", "11", "10", "00"])
Expected Output: [5, 12, -1, -1, -1]
Explanation: For k=1, the cheapest option is the A-only model costing 3 plus the B-only model costing 2, total 5. For k=2, add the "11" model costing 7, total 12. Larger k values cannot be satisfied.
Input: ([4, 1, 6], ["11", "11", "00"])
Expected Output: [1, 5, -1]
Explanation: Only the two "11" models help. The cheapest cost for k=1 is 1, and for k=2 both useful models are needed, costing 1+4=5.
Input: ([5, 5, 2, 8, 1, 4], ["10", "01", "10", "01", "11", "00"])
Expected Output: [1, 8, 21, -1, -1, -1]
Explanation: The "11" model costing 1 satisfies k=1. For additional capability levels, pair the cheapest remaining A-only and B-only models: 2+5=7, then 5+8=13. Prefix totals are 1, 8, and 21.
Input: ([3, 2, 1], ["10", "00", "10"])
Expected Output: [-1, -1, -1]
Explanation: There are no models supporting Feature B, so no k-capable set exists for any k.
Input: ([], [])
Expected Output: []
Explanation: There are no models and no k values to answer.
Hints
- Models with availability "00" can be ignored because costs are positive and they do not help either requirement.
- Think of satisfying one level of k as either choosing one "11" model, or choosing one "10" model together with one "01" model.