Cpp simple dp recursive solution

int solve(int n,int l,int m,string A,string B,string C)
{
if(n==0)
{
return 1;
}
if(l<=0&&m<=0)
{
return 0;
}
int x=0;
int fl=0;
if(l&&A[l-1]==C[n-1])
{
x=max(x,solve(n-1,l-1,m,A,B,C));
fl=1;
}
if(m&&B[m-1]==C[n-1])
{
x=max(x,solve(n-1,l,m-1,A,B,C));
fl=1;
}
if(l&&m&&fl==0)
{
x=max(x,solve(n,l-1,m-1,A,B,C));
}
return x;
}
int Solution::isInterleave(string A, string B, string C) {
int n=C.length();
int l=A.length();
int m=B.length();
return solve(n,l,m,A,B,C);
}

Click here to start solving coding interview questions