int maxProduct(int A[], int n) {
if(n==1) return A[0];
int pMax=0, nMax=0, m = 0;
for(int i=0; i<n; i++){
if(A[i]<0) swap(pMax, nMax);
pMax = max(pMax*A[i], A[i]);
nMax = min(nMax*A[i], A[i]);
m = max(m, pMax);
}
return m;
}
Share C++ code with DP O(1) space O(n) time

Thanks for your post. However it would be better to share solution with correct code format and elaborated thoughts. Please read the Discuss FAQ for more info. Take a look at good sharing example