Dsa
Dynamic Programming
Warm-up
Minimum Change Formulation
You have a certain amount of change in coins of various denominations, and you want to form the minimal amount possible without exceeding a target value. Write a program to determine the minimum number of changes needed to fulfil the target. If it is not possible, return -1.
Input format:
- The first line contains two integers, T (1 ≤ T ≤ 100) and C (1 ≤ C ≤ 100), where T is the target amount and C is the number of coin denominations.
- The second line contains C space-separated integers representing the coin denominations.
Output format:
- A single integer indicating the minimum number of coins needed to meet the target amount, or -1 if it cannot be formed.
Example:
Input:
11 3
1 5 6
Output:
2
Key concepts
dynamic_programmingcombinatoricssimple
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now