Greedy Algorithm to find Minimum number of Coins

Given a value V, if we want to make a change for V Rs, and we have an infinite supply of each of the denominations in Indian currency, i.e., we have an infinite supply of { 1, 2, 5, 10, 20, 50, 100, 500, 1000} valued coins/notes, what is the minimum number of coins and/or notes needed to make the change?

Examples:

Input: V = 70
Output: 2
We need a 50 Rs note and a 20 Rs note.

Input: V = 121
Output: 3
We need a 100 Rs note, a 20 Rs note and a 1 Rs coin.

hello @Kash-Moulik-3715574511847721
on indian currency greedy works.
logic -> as we want to minimize the number of coins ,we should always pick largest possible coin first and then apply the same logic on remaining value.
for example->
V->70
we pick 50 (thats the largest coin we can pick 50<=70)
remaining 70-50 - > 20
apply same logic on 20.
we pick 20 (thats the largest coin we can pick 20<=20)

and we are done so 2 coins needed

cpp soln would be good

@Kash-Moulik-3715574511847721

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.