LCS variation - just 4 line different

int lcs(string A,string B){
int n=A.length(),m=B.length();
int dp[n+1][m+1]={0};
for(int i=0;i<=n;i++){
for(int j=0;j<=m;j++){
if(i==0 || j==0){
else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
return dp[n][m];

int Solution::isInterleave(string A, string B, string C) {

int a=A.size(),b=B.size(),c=C.size();

int x=lcs(A,C);
int y=lcs(B,C);

if(x==a && y==b)return 1;

return 0;


This only works because of poor quality testcases of the platform.

Try this:

Click here to start solving coding interview questions