Count unique numbers that can be generated from N by adding one and removing trailing zeros | Function to count the unique numbers ; If the number has already been visited ; Insert the number to the set ; First step ; Second step remove trailing zeros ; Recur again for the new number ; Driver code
function count_unique ( s , n ) { if ( s . has ( n ) ) return ; s . add ( n ) ; n += 1 ; while ( n % 10 == 0 ) { n = Math . floor ( n / 10 ) ; } count_unique ( s , n ) ; } let n = 10 ; let s = new Set ( ) ; count_unique ( s , n ) ; document . write ( s . size ) ;