Comment by 6510
13 hours ago
One level of nested for loop for each type of coin. (Run them until i*coin is larger than the input)
Populate a 2d lookup array. $7,50 becomes arr[750] = [7,1,0,0,0,0] which represents [7x100,1x50,0x25,0x10,0x5,0x1]
With each loop check if the array entry exists, if so check if that number of coins is larger. [7,1,0... is better than [7,0,2...] because 8 is a better solution than 9!
No comments yet
Contribute on Hacker News ↗