Complete the code to initialize the maximum product variable.
let mut max_product = [1];We start with the first element of the array as the initial maximum product.
Complete the code to update the current maximum product at each step.
max_product = max(max_product, [1]);
The current maximum product is compared with the global max_product to update it.
Fix the error in swapping current_max and current_min when the current number is negative.
if nums[i] < 0 { let temp = [1]; [2] = current_max; current_max = temp; }
When the current number is negative, we swap current_max and current_min to handle sign changes.
Fill both blanks to update current_max and current_min with the current number.
current_max = max(nums[i], current_max [1] nums[i]); current_min = min(nums[i], current_min [2] nums[i]);
We multiply current_max and current_min by nums[i] to update them correctly.
Fill all three blanks to complete the loop that calculates the maximum product subarray.
for i in 1..nums.len() { if nums[i] < 0 { let temp = [1]; [2] = current_max; current_max = temp; } current_max = max(nums[i], current_max [3] nums[i]); current_min = min(current_min * nums[i], nums[i]); max_product = max(max_product, current_max); }
This loop updates current_max and current_min correctly, swapping when negative and multiplying to track products.
