Simple and sweet solution

int dp[150][150][150];
bool check(int i,int j,int k,string str1,string str2,string str3)
{
if(i == str1.length() && j == str2.length() && k == str3.length())
return true;
if(i != (str1.length()-1) && j != (str2.length()) && k == (str3.length()))
return false;
bool answer=false;
if(i < str1.length() && str1[i] == str3[k])
answer |=check(i+1,j,k+1,str1,str2,str3);

if(j < str2.length() && str2[j] == str3[k])
    answer |= check(i,j+1,k+1,str1,str2,str3);

return dp[i][j][k] = answer;

}

int Solution::isInterleave(string A, string B, string C)
{
int n=A.size(),m=B.size(),k=C.size();
//int dp[n][m][k];
memset(dp,-1,sizeof(dp));
return check(0,0,0,A,B,C);
//return dp[n-1][m-1][k-1];
}

Click here to start solving coding interview questions