Buy minimum items without change and given coins | Java implementation of 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
import java . util . * ; class GFG { static int minItems ( int k , int r ) { for ( int i = 1 ; i < 10 ; i ++ ) if ( ( i * k - r ) % 10 == 0 || ( i * k ) % 10 == 0 ) return i ; return 10 ; } public static void main ( String args [ ] ) { int k = 15 ; int r = 2 ; System . out . println ( minItems ( k , r ) ) ; } }