FastPrepMinimum Cost for a Target Weight
Problems/Minimum Cost for a Target Weight

Minimum Cost for a Target Weight

Pace Stock Broking Services logoPace Stock Broking Services● MediumINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This practice preserves the reported power-of-two weights, unlimited purchases, at-least target, bounds, and linear-time follow-up. The second reported sample claimed 23, but the same public discussion identified the valid lower cost 15; the corrected value is used here. The central task match is approximately 98%.

You are given an integer array cost, where cost[i] is the price of one item weighing 2^i. You may buy any nonnegative number of items of every available weight.

Given minWeight, return the minimum total cost whose purchased weight is at least minWeight. The total weight may exceed the target.

Function

minimumCost(cost: int[], minWeight: int) → long

Examples

Example 1

cost = [2,5,7,11,25]minWeight = 26return = 37

Buying three weight-8 items and two weight-1 items reaches weight 26 for cost 37.

Example 2

cost = [3,10,20]minWeight = 5return = 15

Five weight-1 items cost 15.

Constraints

  • 1 <= cost.length <= 30.
  • 1 <= cost[i] <= 10^9.
  • 1 <= minWeight <= 10^9.
  • The answer fits in a signed 64-bit integer.

Source note: The source image is a source-neutral excerpt of the author-reported prompt.

Similar questions at other companies

  • Jump GamePaytm · PHONE SCREENPaytm interview questions
  • Jump Game IINavi · PHONE SCREEN
  • Best Stock Profit With a Sell FeeKaseya · PHONE SCREEN
  • Fewest Jumps to the End or StuckAdobe · PHONE SCREENAdobe interview questions
  • Return a Minimum-Coin Change BreakdownDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Most Relevant Text SpanHebbia · PHONE SCREEN
  • Jump GameZillow · PHONE SCREENZillow interview questions
  • Fewest Jumps to the End of an ArrayRippling · PHONE SCREENRippling interview questions
  • Split Array to Minimize the Largest SumNation with NaMo · PHONE SCREEN
  • Minimum Racks for Server ResourcesGoogle · PHONE SCREENGoogle interview questions
See Pace Stock Broking Services hiring insights
Saved
class Solution {
    public long minimumCost(int[] cost, int minWeight) {
      // Write your code here.
    }
}
Checking account…