Practice · 3 of 5
Fewest Coins
CHALLENGE
Difficulty: intermediate+25 XP
**Description:** Given k coin values and a target sum S, print the minimum number
of coins needed to make S, or -1 if impossible. Each coin may be used any
number of times.
**Input:** Line 1: k S (1 <= k <= 100, 1 <= S <= 100000). Line 2: k values
(1 <= value <= S).
**Output:** One integer — min coins or -1.
**Example:** 3 11 / 1 5 6 -> 2 (5 + 6).
Press Submit to check your solution.
Back to lesson: Practice: Dynamic Programming Problem Set