Cpp solution with few lines

int Solution::isInterleave(string A, string B, string C) {
if(A.length()+B.length()!=C.length())return 0;
vector<vector>dp(A.length()+1,vector(B.length()+1,false));
dp[0][0] = true;
for(int i=1;i<=A.length();i++)if(C[i-1]==A[i-1])dp[i][0] = dp[i-1][0];
for(int i=1;i<=B.length();i++)if(C[i-1]==B[i-1])dp[0][i]=dp[0][i-1];
for(int i = 1;i<=A.length();i++){
for(int j=1;j<=B.length();j++){
if(A[i-1]==C[i+j-1])dp[i][j] = dp[i-1][j];
if(B[j-1]==C[i+j-1])dp[i][j] = (dp[i][j]|dp[i][j-1]);
}
}
return dp[A.length()][B.length()];
}

Click here to start solving coding interview questions