Problem Link : Distinct Subsequence
solution :Solution Link
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long
#define endl "\n"
#define boost \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define Mod (int)(1e9+ 7)
#define fl(i, a,b) for(int i = a; i < b; i++)
void func(string s, string p, string temp, int idx,int &ans){
// temp == p
if(temp == p){
ans += 1;
return;
}
// size of temp > size of p
if(temp.length() >= p.length() || idx >= s.size() ){
return;
}
func(s, p, temp + s[idx], idx+1, ans);
func(s, p, temp, idx+1, ans);
return;
}
int solve(string s, string p){
int ans = 0;
if(s.length() < p.length()){
return ans;
}
func(s, p, "", 0, ans);
return ans;
}
int main() {
boost;
int tc;
cin>>tc;
while(tc--){
string s, t;
cin>>s>>t;
cout<<solve(s, t)<<endl;
}
return 0;
}
test case : “bccbcdcabadabddbccaddcbabbaaacdba” “bccbbdc”
I got segmentation error.
I am not finding the error in this solution.
plz help finding the error