Smallest x such that 1 * n , 2 * n , ... x * n have all digits from 1 to 9 | Returns smallest value x such that 1 * n , 2 * n , 3 * n ... x * n have all digits from 1 to 9 at least once ; taking temporary array and variable . ; iterate till we get all the 10 digits at least once ; checking all the digits ; driver program
function smallestX ( n ) { let temp = Array . from ( { length : 10 } , ( _ , i ) => 0 ) ; for ( let i = 0 ; i < 10 ; i ++ ) temp [ i ] = 0 ; if ( n == 0 ) return - 1 ; let count = 0 , x = 0 ; for ( x = 1 ; count < 10 ; x ++ ) { let y = x * n ; while ( y > 0 ) { if ( temp [ y % 10 ] == 0 ) { count ++ ; temp [ y % 10 ] = 1 ; } y /= 10 ; } } return x - 1 ; } let n = 5 ; document . write ( smallestX ( n ) ) ;