Last updated
Was this helpful?
Last updated
Was this helpful?
The change-making problem, also known as minimum coin change problem, addresses the question of finding the minimum number of coins (of certain denominations) that add up to a given amount of money.
The Idea: The central idea is to build a tree BFS style. The root is initially the amount of change, and the child of every node is defined as parent - denomination
. Since our goal is not only to return the minimum amount of coins possible, but which coins these are, our structure is also going to carry parent nodes from so we backtrack from earlier nodes. I also sorted the denominations in acending order. That way, when the moment a denomination fails to fit the current amount of the change, I know I can ignore the remaining denominations.
Complexity: ?
Testing: