3 ms·
Any problem can be solved by a sufficient number of nested for loops. (if you have enough time)
by meindnoch 1y ago
Any problem can be solved by a sufficient number of nested for loops.
(if you have enough time)
- scotty79 1y agoAnd a stack.
- 6510 1y agoOne 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!