Solve the maximum product subarray problem and explain how you handle negatives and zeros.
Implement the function below for a non-empty integer array. Return the largest product of any contiguous, non-empty subarray, including single-element subarrays. Explain why both the maximum and minimum products ending at each position must be tracked.
def max_product(nums):