The Task
Build a function that takes a string of coins ending with an item index, and generates change as a string of coins using the least amount of coins possible.
The following are the items that can be bought (0-indexed):
[0.45, 0.60, 0.75, 0.95, 1.10, 1.25, 1.40, 1.50, 1.75, 2.00]
The following are the coins that can be used, with their abbreviations:
n = 0.05
d = 0.10
q = 0.25
D = 1.00
If an invalid item is selected, or the coins supplied are not enough to purchase the item, all $ is returned in the least number of coins possible.
If exact change is given, an empty string should be returned
Test Cases
Dq4 = dn
qqqq4 = D
qqddddd10 = D
qqn0 = d
Dddd5 = n
qq0 = n
DD3 = Dn
Dd4 =
DDnn9 = d
Assume that input will only contain valid coin characters and will always terminate in an integer.
This is my first posted question, so be please be gentle when telling me how I screwed up asking it. :)