Buy minimum items without change and given coins | Javascript program of the above approach ; See if we can buy less than 10 items Using 10 Rs coins and one r Rs coin ; We can always buy 10 items ; Driver code
function minItems ( k , r ) { for ( let i = 1 ; i < 10 ; i ++ ) if ( ( i * k - r ) % 10 == 0 || ( i * k ) % 10 == 0 ) return i ; return 10 ; } let k = 15 ; let r = 2 ; document . write ( minItems ( k , r ) ) ;