Minimum coin change

A ticket costs 6. You have as many coins of values 1, 3 and 4 as you like. How few coins can you hand over to pay exactly?

Visit amounts in increasing order. When a smaller amount comes up, its answer is already in the table.

Add one last coin to the number needed for the remainder.

For amount A and n denominations, time is O(A × n) and space is O(A).