Bird
Raised Fist0
DSA Typescriptprogramming~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What does the "Coin Change Minimum Coins" problem ask you to find?
easy
A. The maximum amount of money you can make with given coins
B. The total number of different coins available
C. The least number of coins needed to make a given amount
D. The sum of all coin values

Solution

  1. Step 1: Understand the problem goal

    The problem asks for the minimum number of coins needed to make a specific amount.
  2. Step 2: Differentiate from other coin problems

    It is not about counting coins or maximum amount, but minimizing coin count for exact amount.
  3. Final Answer:

    The least number of coins needed to make a given amount -> Option C
  4. Quick Check:

    Minimum coins = least number needed [OK]
Hint: Focus on minimum coins to form amount, not total coins [OK]
Common Mistakes:
  • Confusing minimum coins with total coin types
  • Thinking problem asks for maximum amount
  • Ignoring the exact amount requirement
2. Which of the following is the correct TypeScript function signature for a coin change minimum coins function?
easy
A. function minCoins(coins: number[], amount: number): number
B. function minCoins(amount: number, coins: number[]): void
C. function minCoins(coins: number, amount: number[]): number[]
D. function minCoins(coins: string[], amount: string): number

Solution

  1. Step 1: Check parameter types and order

    The function should take an array of coin values (number[]) and an amount (number).
  2. Step 2: Check return type

    The function returns a number representing minimum coins needed.
  3. Final Answer:

    function minCoins(coins: number[], amount: number): number -> Option A
  4. Quick Check:

    Correct types and return number [OK]
Hint: Coins array first, amount second, returns number [OK]
Common Mistakes:
  • Swapping parameter order
  • Using wrong types like string instead of number
  • Returning void or array instead of number
3. What is the output of the following TypeScript code?
function minCoins(coins: number[], amount: number): number {
  const dp = Array(amount + 1).fill(amount + 1);
  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] > amount ? -1 : dp[amount];
}

console.log(minCoins([1, 2, 5], 11));
medium
A. 2
B. 3
C. -1
D. 5

Solution

  1. Step 1: Understand dp array initialization

    dp array size is 12 (0 to 11), initialized with 12 (amount+1), dp[0] = 0.
  2. Step 2: Calculate dp values for amount 11

    Using coins 1,2,5, minimum coins for 11 is 3 (5+5+1).
  3. Final Answer:

    3 -> Option B
  4. Quick Check:

    Minimum coins for 11 with [1,2,5] = 3 [OK]
Hint: Use dp array to track min coins for each amount [OK]
Common Mistakes:
  • Returning dp[amount] without checking if > amount
  • Misunderstanding dp initialization
  • Confusing coin values and indices
4. Identify the bug in this TypeScript code for minimum coins:
function minCoins(coins: number[], amount: number): number {
  const dp = new Array(amount + 1).fill(0);
  dp[0] = 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];
}
medium
A. The condition should be coin <= i, not coin < i
B. dp array should be initialized with Infinity, not 0
C. dp[0] should be Infinity, not 0
D. Return statement should check dp[amount] > Infinity

Solution

  1. Step 1: Check coin usage condition

    The condition 'coin < i' skips cases where coin equals i, missing exact matches.
  2. Step 2: Correct condition to include equal coins

    Change condition to 'coin <= i' to allow using coin equal to current amount.
  3. Final Answer:

    The condition should be coin <= i, not coin < i -> Option A
  4. Quick Check:

    Include coin equal to amount [OK]
Hint: Use <= to include exact coin matches [OK]
Common Mistakes:
  • Using < instead of <= in coin check
  • Initializing dp array incorrectly
  • Wrong return condition check
5. Given coins = [2, 3, 7] and amount = 13, what is the minimum number of coins needed? Use the coin change minimum coins approach.
hard
A. -1
B. 4
C. 2
D. 3

Solution

  1. Step 1: Try combinations to form 13

    Possible combos: 7+3+3 = 3 coins, 2+2+2+7 = 4 coins, etc.
  2. Step 2: Identify minimum coins

    Minimum coins is 3 using 7, 3, and 3.
  3. Final Answer:

    3 -> Option D
  4. Quick Check:

    7+3+3 = 13 with 3 coins [OK]
Hint: Try largest coins first to minimize count [OK]
Common Mistakes:
  • Assuming no solution (-1) without checking combos
  • Counting coins incorrectly
  • Ignoring combinations with repeated coins
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard