EvalFrame Technical Mock Interviews & Coding Practice

Coin Change

Medium · Dynamic Programming · Algorithm problem · all problems

You are given an integer array `coins` representing coins of different denominations and an integer `amount` representing a total amount of money. Return the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return `-1`. You may assume that you have an infinite number of each kind of coin. **Examples:** ```typescript coinChange([1, 2, 5], 11) // 3 (5 + 5 + 1) coinChange([2], 3) // -1 coinChange([1], 0) // 0 ```

Solve It in the BrowserPractice Explaining It Out Loud

Optimal Approach

  • Time complexity: O(amount * coins.length)
  • Space complexity: O(amount)

Iterates through all values from 1 to amount for each coin denomination.

Follow-Up Questions Interviewers Ask About Coin Change

  • Why does greedy coin selection (largest first) fail for general denominations?
    For coins [1, 3, 4] and target 6, greedy picks 4 + 1 + 1 (3 coins), whereas the optimal is 3 + 3 (2 coins).

Practice the full problem with execution, tests, and AI code review in the interactive lab — then rehearse explaining your solution in a live voice mock interview.