Coin Change DP | Algorithm Interview | Skill-Lync Resources
Medium Algorithms Dynamic Programming

How do you solve the coin change problem using DP?

Answer

Given coins and target amount, find minimum coins needed (or number of ways). For minimum coins: dp[i] = min coins for amount i. Initialize dp[0]=0, others=infinity. For each amount i and each coin c, if c<=i: dp[i] = min(dp[i], dp[i-c]+1). For counting ways: dp[i] += dp[i-c]. Time O(amount * coins), space O(amount). The greedy approach doesn't always work (e.g., [1,3,4] making 6).

Master These Concepts with IIT Certification
IIT Certified

Master These Concepts with IIT Certification

175+ hours of industry projects. Get placed at Bosch, Tata Motors, L&T and 500+ companies.

Relevant for Roles

Software Engineer Algorithm Developer Backend Developer