0
0
DSA Typescriptprogramming~20 mins

Coin Change Minimum Coins in DSA Typescript - Practice Problems & Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Coin Change Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of minimum coins for amount 11
What is the output of the following TypeScript code that finds the minimum number of coins needed to make amount 11 using coins [1, 2, 5]?
DSA Typescript
function minCoins(coins: number[], amount: number): number {
  const dp = new Array(amount + 1).fill(Infinity);
  dp[0] = 0;
  for (let i = 1; i <= amount; i++) {
    for (const coin of coins) {
      if (coin <= i) {
        dp[i] = Math.min(dp[i], dp[i - coin] + 1);
      }
    }
  }
  return dp[amount] === Infinity ? -1 : dp[amount];
}

console.log(minCoins([1, 2, 5], 11));
A3
B4
C5
D-1
Attempts:
2 left
💡 Hint
Think about how many coins of 5, 2, and 1 can sum to 11 with minimum count.
Predict Output
intermediate
2:00remaining
Output when no solution exists
What is the output of this TypeScript code when trying to make amount 3 with coins [2, 4]?
DSA Typescript
function minCoins(coins: number[], amount: number): number {
  const dp = new Array(amount + 1).fill(Infinity);
  dp[0] = 0;
  for (let i = 1; i <= amount; i++) {
    for (const coin of coins) {
      if (coin <= i) {
        dp[i] = Math.min(dp[i], dp[i - coin] + 1);
      }
    }
  }
  return dp[amount] === Infinity ? -1 : dp[amount];
}

console.log(minCoins([2, 4], 3));
A1
B-1
C0
D3
Attempts:
2 left
💡 Hint
Check if amount 3 can be formed by any combination of 2 and 4.
🔧 Debug
advanced
2:00remaining
Identify the bug in coin change code
The following TypeScript code is intended to find the minimum number of coins needed for a given amount. What is the bug causing incorrect results?
DSA Typescript
function minCoins(coins: number[], amount: number): number {
  const dp = new Array(amount + 1).fill(0);
  for (let i = 1; i <= amount; i++) {
    dp[i] = Infinity;
    for (const coin of coins) {
      if (coin <= i) {
        dp[i] = Math.min(dp[i], dp[i - coin] + 1);
      }
    }
  }
  return dp[amount] === Infinity ? -1 : dp[amount];
}

console.log(minCoins([1, 3, 4], 6));
AReturn statement should check for dp[0] instead of dp[amount]
BLoop should start from i = 0 instead of 1
Cdp array initialized with zeros causes wrong base case
DCoins array should be sorted before processing
Attempts:
2 left
💡 Hint
Check how dp array is initialized and how it affects calculations.
🧠 Conceptual
advanced
1:30remaining
Time complexity of coin change minimum coins algorithm
What is the time complexity of the dynamic programming solution for the coin change minimum coins problem with n coins and amount m?
AO(n * m)
BO(n + m)
CO(n^m)
DO(m^n)
Attempts:
2 left
💡 Hint
Consider nested loops over coins and amounts.
🚀 Application
expert
3:00remaining
Minimum coins with unlimited and limited coin usage
Given coins [1, 3, 4] and amount 6, what is the minimum number of coins needed if coin 3 can only be used once, but others unlimited?
A2
B-1
C4
D3
Attempts:
2 left
💡 Hint
Think about using coin 3 once and then filling the rest with 1 or 4.