Minimum Cost to Reach a Target Weight
Updated
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.
More Chubb Online Assessment questions
- Count Pairs with K Divisible Values in the IntervalOA · Seen Oct 2026
- Index of the Maximum After Left RotationsOA · Seen Oct 2026
- Maximize Revenue from Decreasing InventoryOA · Seen Oct 2026
- Minimize the Maximum Array ElementOA · Seen Oct 2026
- Minimum Distinct Prefix CostOA · Seen Oct 2026
- Flat JSON Value DifferencesOA · Seen Sep 2026
- Maximum Student-Teacher DistanceOA · Seen Sep 2026
- Minimum Last-Element RelocationsOA · Seen Sep 2026
- Most Visited Sprint MarkerOA · Seen Sep 2026
- How Many Sentences?OA · Seen Sep 2026
Similar questions at other companies
- Maximize K-Element AND with an Increment BudgetAmazon · OA
- Maximum XOR Elimination ScoreRippling · OA
- Minimum Halvings for Alternating ParityIBM · OA
- Server SelectionPoint72 · OA
- Minimum Servers for an Exact LoadJP Morgan Chase · OA
- Get Max Or SumMicrosoft · OA
- Fewest Steps to Build an Array from ZerosExpedia · OA
- Minimum Row Deletions to Prevent a Target ORInMobi · ONSITE INTERVIEW
- Minimum Cost for a Target WeightPace Stock Broking Services · PHONE SCREEN
- Hard Disk Clustering CostConfluent · OA