Doubt in recusrion part

Sir, in the recursion line, I found it difficult to understand.

Hey @pranjal123 , See what is happening is we want to find the min number of coins in which we can change the given amount. And we have certain denominations in an array .

Let the amount be X
Let the array be coins .
so whenever we use a coin from the coins array our X amount is now changes into (X - coins[i]) + (coins[i]) .
Now we know that coins[i] can be changed using 1 coin because we have the coin of that denomination

Now , let us assume that X- coins[i] can be changes using a coins .
so total amount X can be changed using a+1 coins . (1 for that coins[i] ) .

We are doing the same thing in the code as well and taking the min of every case we get .

Also , X-coins[i] >=0 it should always be true because let’s say you have 10 rupee coin and you want to change it using 20 rupee coin. Isn’t it weird? how can you change 10 rupee coin using 20 rupee . That’s why this condition is important

I hope you understand now .

Hope it helps :blush: .
If your doubt is now resolved please mark it as resolved and rate me accordingly .
Else you can further questions here .
Thankyou