CodeMentor.
Ask AIProblemsLearnC++TCSCore CSHRProgress
0Lv 1
ProblemsIntro Dynamic Programming

Coin Change

Medium
LeetCode
3/3
MediumIntro Dynamic ProgrammingLeetCode #322

Coin Change

Fewest coins for amount. dp[x] = min over coin of dp[x-coin]+1.

Examples

Example 1

Input

3 11
1 2 5

Output

3
Example 2

Input

1 3
2

Output

-1

Stuck? Take a nudge

C++17Autosaves