Complete the code to initialize the maximum product with the first element of the array.
int maxProduct = [1];We start with the first element as the initial maximum product because the product subarray must include at least one element.
Complete the code to update the maximum product after processing each element.
maxProduct = Math.max(maxProduct, [1]);
We update maxProduct by comparing it with the current maximum product ending at the current index.
Fix the error in swapping currMax and currMin when nums[i] is negative.
if (nums[i] < 0) { int temp = [1]; [2] = currMax; currMax = temp; }
When the current number is negative, the maximum and minimum products swap because multiplying by a negative flips signs.
Fill both blanks to update currMax and currMin correctly for the current element.
currMax = Math.max(nums[i], currMax [1] nums[i]); currMin = Math.min(nums[i], currMin [2] nums[i]);
We multiply the current number with the previous max and min to find new max and min products ending at this index.
Fill all three blanks to complete the loop that calculates the maximum product subarray.
for (int [1] = 1; [2] < nums.length; [3]++) { if (nums[i] < 0) { int temp = currMin; currMin = currMax; currMax = temp; } currMax = Math.max(nums[i], currMax * nums[i]); currMin = Math.min(nums[i], currMin * nums[i]); maxProduct = Math.max(maxProduct, currMax); }
The loop variable is 'i' starting from 1 to iterate through the array elements.
