Failing for large test cases


#1

I solved it using stack.
Code:

 int Solution::isMatch(const string A, const string B) {
 stack<pair<int,int>> s;
int j=B.size()-1,i=A.size()-1;
while(i>=0)
{
    if(j>=0 && (A[i]==B[j] || B[j]=='.'))
    {
        i--;j--;
    }
    else if(j>=0 && B[j]=='*')
    {
        if(B[j-1]==A[i] || B[j-1]=='.')
        {
            s.push({i,j});
            i--;
            j-=2;
        }
        else
        {
            if(s.empty())
            {
                j-=2;
            }
            else
            {
                pair<int,int> x=s.top();
                j=x.second;
                i=x.first-1;
                s.pop();
            }
        }
    }
    else if(!s.empty())
    {
        pair<int,int> x=s.top();
        j=x.second;
        i=x.first-1;
        s.pop();
    }
    else
    {
        return 0;
    }
}
while(j>=0 && B[j]=='*')
{
    j-=2;
}
if(j>=0)
{
    return 0;
}
return 1;
}

On submitting it shows:
Wrong answer. Code might be failing for large test cases. Please tell where it goes wrong.