text: C ++ program for the above approach
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; void dfs ( int temp , int n , vector < int > & sol ) ; void lexNumbers ( int n ) { vector < int > sol ; dfs ( 1 , n , sol ) ; cout << " [ " << sol [ 0 ] ; for ( int i = 1 ; i < sol . size ( ) ; i ++ ) cout << " , ▁ " << sol [ i ] ; cout << " ] " ; } void dfs ( int temp , int n , vector < int > & sol ) { if ( temp > n ) return ; sol . push_back ( temp ) ; dfs ( temp * 10 , n , sol ) ; if ( temp % 10 != 9 ) dfs ( temp + 1 , n , sol ) ; }