Simple and sweet solutionn


#1

int Solution::maxProduct(const vector &A)
{
if(A.size() == 0)
return 0;
int maxcount = A[0];
int mincount = A[0];
int globalcount = A[0];
for(int i = 1;i<A.size();i++)
{
if(A[i] < 0)
swap(maxcount,mincount);
maxcount = max(A[i],A[i]*maxcount);
mincount = min(A[i],A[i]*mincount);

    globalcount = max(globalcount,maxcount);
}
return globalcount;

}