The algorithm: 1. Create dp array of size amount+1, initialized to infinity (or amount+1) 2. Set dp[0] = 0 3. For each amount from 1 to target: - For each coin, if coin <= current amount: - dp[amount] = min(dp[amount], dp[amount - coin] + 1) 4. Return dp[target] if it's not infinity, else −1
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
$ curl repovive.com/roadmaps/maang-interview-prep/dynamic-programming/coin-change-solution
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████████████████████████████████████████████████████████████████████████████████████████