Minimum Cost to Reach a Target Weight
Problem statement
Item type i has weight 2^i and costs cost[i]. You may buy any nonnegative number of every type.
Return the minimum total cost whose purchased weight is at least minWeight.
Function
minimumWeightCost(cost: int[], minWeight: int) → longExamples
Example 1
cost = [2,5,7,11,25]minWeight = 26return = 37Normalization and the high-to-low scan compare exact coverage with the cheapest permissible overshoot.
Example 2
cost = [1]minWeight = 0return = 0Normalization and the high-to-low scan compare exact coverage with the cheapest permissible overshoot.
Example 3
cost = [3]minWeight = 5return = 15Normalization and the high-to-low scan compare exact coverage with the cheapest permissible overshoot.
Constraints
1 <= cost.length <= 31.1 <= cost[i] <= 10^9.0 <= minWeight <= 10^9.- The answer fits a signed 64-bit integer.
Source note: Author-written prompt excerpt retained for source fidelity.