Skip to content
Katabench
Try free

Coin Change (Fewest Coins)

Medium About 25 min Free, no account needed

The fewest coins that make the amount, or -1.

The brief

Given coin denominations coins (unlimited supply) and an amount, return the fewest coins that sum to amount, or -1 if it cannot be made.

The performance bar

The obvious approach recurses over every coin at every amount, exponential. The hidden test asks for amount 10,000 with coins [1, 5, 7], which an exponential search will never finish. You need to avoid recomputing the answer for the same amount repeatedly; an O(amount * coins) solution clears the bar.

Starter code

C#
using System;

public class Solution
{
    // TODO: return the fewest coins summing to amount; -1 if impossible.
    public int CoinChange(int[] coins, int amount)
    {
        throw new NotImplementedException();
    }
}

How it is graded

Visible examples help you iterate. Hidden tests then cover edge cases and larger inputs, and every test reports server-measured time and allocated bytes.

C# coding challenges →

Related guides

What it practices

Dynamic programming
Define subproblems and a recurrence, then reuse solved subproblems instead of recomputing them.

Do these first

Related katas