Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

coins =
amount =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Unbounded knapsack for minimum coins.

Approach

dp[a] = minimum coins to make amount a. For each a, try every coin c and relax from dp[a-c] + 1.

Why it works

Any optimal solution for a ends with some last coin c, leaving subproblem a-c.

Code
Loading...
Complexity
Time: O(amount * numCoins)
Space: O(amount)
Solution
Updated: 2026-02-23

Idea

Unbounded knapsack for minimum coins.

Approach

dp[a] = minimum coins to make amount a. For each a, try every coin c and relax from dp[a-c] + 1.

Why it works

Any optimal solution for a ends with some last coin c, leaving subproblem a-c.

Code
Loading...
Complexity
Time: O(amount * numCoins)
Space: O(amount)