Nth term of a sequence formed by sum of current term with product of its largest and smallest digit | Function to find integer ; because 1 st integer is K itself ; Initialize min_d and max_d ; updating min_d and max_d ; break if min digit is 0 ; Driver code
function find ( K , N ) { N -- ; while ( N -- ) { let curr_term = K ; let min_d = 9 ; let max_d = 0 ; while ( curr_term > 0 ) { let r = curr_term % 10 ; min_d = Math . min ( min_d , r ) ; max_d = Math . max ( max_d , r ) ; curr_term = Math . floor ( curr_term / 10 ) ; } if ( min_d == 0 ) { break ; } K = K + min_d * max_d ; } return K ; } let K = 487 ; let N = 2 ; document . write ( find ( K , N ) + " " ) ;