Crack the pass question ccrr 2021

https://www.codechef.com/CCRR2021/problems/CCRR002/
this is the question
and the following this is my solution Solution: 42124200 | CodeChef

But it’s not a good solution if the length increases can anyone suggest any other approach for this question if attempted then pls share your code too.

you need not to do for every test case you can do with recursion
it’s basic recursion :slight_smile:

#include<bits/stdc++.h> 
#define ll long long 
#define pb(i) push_back(i)
#define vii vector<vector<int>> 
#define vi vector<int> 
#define vll vector<vector<ll>> 
using namespace std;
const int inf = 1e9 + 7;
void solve(int n,string res){
	if(res.size()==n){
		cout<<res<<endl;
		return ;
	}
	for(int i=1; i<=9; i++){
		res+=to_string(i);
		solve(n,res);
		res.pop_back();
	}
}
void test_case(){
	int l; cin>>l;
	solve(l,"");
}

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
  
    int t = 1;  cin>>t;
    while(t--){
    	test_case();
    	//cout<<"\n";
    }
    return 0;
}