Please check whats the mistake in this code got accepted in leetcode but not here


#1

unordered_map<string,bool> mp;
bool check(string A, string B, string C,int l,int m,int n,int p1,int p2,int p3)
{
if(p3==n)
{
return (p1==l && p2==m)?true:false;
}

string key = to_string(p1) + "*" + to_string(p2) + "*" + to_string(p3);
if(mp.find(key)!=mp.end())
    return mp[key];
if(p1==l)
    return mp[key] = B[p2]==C[p3] ? check(A,B,C,l,m,n,p1,p2+1,p3+1):false;
if(p2==m)
    return mp[key] = A[p1]==C[p3] ? check(A,B,C,l,m,n,p1+1,p2,p3+1):false;

bool one = false , two = false;
if(A[p1] == C[p3])
    one = check(A,B,C,l,m,n,p1+1,p2,p3+1);
if(B[p2] == C[p3])
    two = check(A,B,C,l,m,n,p1,p2+1,p3+1);
    
return mp[key] = one or two;

}
int Solution::isInterleave(string A, string B, string C) {
int l = A.size(),m=B.size(),n=C.size();

if(n != l+m)    return false;
if(A.length()==0){
   return B==C;

}
if(B.length()==0)return A==C;
if(C.length()==0)return false;

return check(A,B,C,l,m,n,0,0,0);
}