Accepted my wrong solution bcz of weak test cases


#1

the test cases are weak and accepted my wrong solution.

for input as [ -1, -1, -1,-1 ] we should return 1 but my solution returned 0.


#2
int Solution::maxProduct(const vector<int> &A) {
    int n=A.size();
    
    if(n==0) return 0;
    
    long long max_p=1,max_n=-1,ans=A[0];
    int neg_c=0;
    
    if(ans>0) max_p=ans;
    else if(ans<0)
    {
        max_n=ans;
        neg_c++;
    }
    
    for(int i=1;i<n;i++)
    {
        long long temp=A[i];
        if(A[i]>0)
        {
            max_p=max(max_p,max_p*temp);
            max_n=min(-1*1LL,max_n*temp);
        }
        else if(A[i]==0)
        {
            max_p=1;
            max_n=-1;
            neg_c=0;
        }
        else
        {
            if(neg_c%2==0)
            {
                max_n=max_p*temp;
                max_p=1;
                neg_c++;
            }
            else
            {
                max_p=max_n*temp;
                max_n=temp;
                neg_c++;
            }
        }
        
        if(temp==0)
        {
            ans=max(ans,temp);
            continue;
        }

        if(ans<max_p and max_p!=1)
        {
            ans=max_p;
        }
        else if(max_p==1 and temp==1)
        {
            ans=max(ans,max_p);
        }
    }
    
    return ans;
}