Problem · Dynamic Programming
Minimum Coins for a Target
Learn this problemProblem statement
Given an integer array coins of positive denominations and a nonnegative integer target, return the minimum number of coins needed to sum exactly to target.
You may use each denomination any number of times. Return -1 when no combination reaches the target. A target of 0 requires 0 coins.
Function
minCoins(coins: int[], target: int) → intExamples
Example 1
coins = [1,2,5]target = 11return = 3The target can be formed as 5 + 5 + 1, using three coins, and no two-coin combination reaches 11.
Example 2
coins = [2]target = 3return = -1No number of coins with denomination 2 can sum to 3.
Example 3
coins = [2,3]target = 0return = 0The empty selection already has sum 0.
Constraints
1 <= coins.length <= 2001 <= coins[i] <= 1000000 <= target <= 100000- Duplicate denominations may appear in
coins.
More infosys problems
- Swap Two Numbers Without a Third VariableONSITE INTERVIEW · Seen Aug 2026
- Count Valid A-B-C Sequences Under a Modulo-Four RuleOA · Seen Aug 2026
- Maximum Product of a Strictly Increasing Contiguous SubarrayOA · Seen Aug 2026
- Minimum Cost to Assign Candidates to Two CitiesOA · Seen Aug 2026
- Merge Two Sorted Arrays In PlaceONSITE INTERVIEW · Seen Jul 2026
- Sort Sentence WordsONSITE INTERVIEW · Seen Jul 2026
- Minimum Path Sum With Grid SwitchesONSITE INTERVIEW · Seen May 2026
- Maximum Subarray Sum After SwapsOA · Seen Feb 2026