Find minimum number of currency notes and values that sum to given amount | function to count and print currency notes ; count notes using Greedy approach ; Print notes ; driver code
function countCurrency ( amount ) { let notes = [ 2000 , 500 , 200 , 100 , 50 , 20 , 10 , 5 , 1 ] ; let noteCounter = Array ( 9 ) . fill ( 0 ) ; for ( let i = 0 ; i < 9 ; i ++ ) { if ( amount >= notes [ i ] ) { noteCounter [ i ] = Math . floor ( amount / notes [ i ] ) ; amount = amount - noteCounter [ i ] * notes [ i ] ; } } document . write ( " " + " " ) ; for ( let i = 0 ; i < 9 ; i ++ ) { if ( noteCounter [ i ] != 0 ) { document . write ( notes [ i ] + " " + noteCounter [ i ] + " " ) ; } } } let amount = 868 ; countCurrency ( amount ) ;