So I was trying to submit my solution on LeetCode and if did not get accepted because we need to return -1 whenever forming amount ‘n’ is not possible to form through our coins. Can you please help me out?
DP- Coin Change Bottom Up
hello @rachitbansal2500
add that highlighted condition in ur code. basically that condtion is checking whether dp[i-coins[j]] is valid or not . if it is valid than only take its minimum with ans otherwise ignore.
1 Like
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.