This problem is the sequel problem to 322 Coin Change and there’s little difference between the two problems’ requirements. The first one needed us to minimize the number of coins we could use to make up amount
.
In here, we need to compute the number of different ways amount
can be made from the given coins.
Code
Python3
Big O Analysis
-
Runtime
The runtime complexity here is since we are memoising, needing to visit all elements only once.
-
Memory
The memory usage is since we use the
collections.defaultdict
object to store the memoised values.
— A