max_so_far
and min_so_far
to the first element of the array, and result
to max_so_far
.max_so_far
and min_so_far
by considering the current number, the product of the current number and the previous max_so_far
, and the product of the current number and the previous min_so_far
.max_so_far
with the maximum of these three values, and min_so_far
with the minimum.result
with the maximum of result
and the new max_so_far
.result
as the largest product of any subarray.