Easy peasy code without DP!

void helper(string A,string B,string C,int ind1,int ind2,int ind3,int &flag){
    if(ind3>=C.size()){
        if(ind1>=A.size()-1 && ind2>=B.size()-1)
            flag=1;
        return ;
    }
    if(A[ind1]==C[ind3] && B[ind2]!=C[ind3]){
        if(ind1==A.size()-1)
            helper(A,B,C,ind1,ind2,ind3+1,flag);
        else
            helper(A,B,C,ind1+1,ind2,ind3+1,flag);
    }
    else if(B[ind2] == C[ind3] && A[ind1]!=C[ind3]){
        if(ind2==B.size()-1)
            helper(A,B,C,ind1,ind2,ind3+1,flag);
        else
            helper(A,B,C,ind1,ind2+1,ind3+1,flag);
    }
    else if(B[ind2] == C[ind3] && A[ind1] == C[ind3]){
        if(ind2==B.size()-1)
            helper(A,B,C,ind1+1,ind2,ind3+1,flag);
        else
            helper(A,B,C,ind1,ind2+1,ind3+1,flag);
        if(ind1==A.size()-1)
            helper(A,B,C,ind1,ind2+1,ind3+1,flag);
        else
            helper(A,B,C,ind1+1,ind2,ind3+1,flag);
    }
}
int Solution::isInterleave(string A, string B, string C) {
    int flag=0;
    helper(A,B,C,0,0,0,flag);
    if(flag)
        return 1;
    return 0;
}
Click here to start solving coding interview questions