text: JavaScript program for the above approach
code: function lexNumbers ( n ) { var sol = [ ] ; dfs ( 1 , n , sol ) ; document . write ( " " + sol [ 0 ] ) ; for ( var i = 1 ; i < sol . length ; i ++ ) document . write ( " " + sol [ i ] ) ; document . write ( " " ) ; } function dfs ( temp , n , sol ) { if ( temp > n ) return ; sol . push ( temp ) ; dfs ( temp * 10 , n , sol ) ; if ( temp % 10 != 9 ) dfs ( temp + 1 , n , sol ) ; }