int maxProduct(vector<int>& nums) {
int curMax, curMin, res;
curMax = curMin = res = nums[0];
for (unsigned int i=1; i<nums.size(); i++) {
int tmp = curMin;
curMin = min(nums[i], min(curMax*nums[i], curMin*nums[i]));
curMax = max(nums[i], max(curMax*nums[i], tmp*nums[i]));
res = max(res, curMax);
}
return res;
}
C++ dp solution using O(1) extra space.


For this solution, I have some doubts in mind:
 curMax/curMin may not be contiguous with i, so I don't think we can safely multiply nums[i] with curMax or curMin. (this is the case when there is 0 in middle, it partitions the array)
 And what happens if there is 0 at start of array, then max and min both are ZERO.
Did I miss anything?