AlgoMaster Logo

Coin Change

Ashish

Ashish Pratap Singh

medium

Problem Description

Solve it on LeetCode

Approaches

1. Brute Force - Recursive

The brute force approach is to try all possible combinations of coins to determine the minimum number needed for the given amount. The intuition is to recursively subtract each coin from the amount and solve the problem for the reduced amount until the amount is 0. This tries out all possible combinations.

Code:

2. Dynamic Programming - Top Down (Memoization)

To optimize the recursive solution, we use memoization to store the results of subproblems to avoid redundant calculations. The idea is the same as the recursive approach but with a cache to store previously computed results.

Code:

3. Dynamic Programming - Bottom Up (Tabulation)

The most efficient approach uses dynamic programming with a bottom-up technique by creating a table to store the minimum coins required for all values from 0 to the amount. We build the solution iteratively.

Code: