text: Python program for the above approach
code: def lexNumbers ( n ) : NEW_LINE INDENT sol = [ ] NEW_LINE dfs ( 1 , n , sol ) NEW_LINE print ( " [ " , sol [ 0 ] , end = " " , sep = " " ) NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT print ( " , ▁ " , sol [ i ] , end = " " , sep = " " ) print ( " ] " ) NEW_LINE DEDENT DEDENT def dfs ( temp , n , sol ) : NEW_LINE INDENT if ( temp > n ) : NEW_LINE INDENT return NEW_LINE DEDENT sol . append ( temp ) NEW_LINE dfs ( temp * 10 , n , sol ) NEW_LINE if ( temp % 10 != 9 ) : NEW_LINE INDENT dfs ( temp + 1 , n , sol ) NEW_LINE DEDENT DEDENT