text function coinChange(coins, amount): dp = array of size (amount + 1) filled with (amount + 1) dp[0] = 0 for i from 1 to amount: for coin in coins: if coin <= i: dp[i] = min(dp[i], dp[i - coin] + 1) if dp[amount] > amount: return -1 return dp[amount] Time complexity: where n is the number of coins. Space complexity: for the dp array.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
$ curl repovive.com/roadmaps/maang-interview-prep/dynamic-programming/coin-change-pseudocode
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████████████████████████████████████████████████████████████████████████████████████████