Step 1: Start with first element: maxProd = 2, minProd = 2, result = 2
maxProd=2, minProd=2, result=2
Why: Initialize with first element to start tracking products
Step 2: Process -3: swap maxProd and minProd because -3 is negative
maxProd=2, minProd=2 (before swap)
After swap: maxProd=2, minProd=2
Why: Negative flips max and min, so swap to keep correct tracking
Step 3: Update maxProd = max(-3, 2 * -3) = max(-3, -6) = -3; minProd = min(-3, 2 * -3) = min(-3, -6) = -6
maxProd=-3, minProd=-6, result=2
Why: Calculate new max and min products including current element
Step 4: Update result = max(2, -3) = 2
result=2
Why: Keep track of the highest product found so far
Step 5: Process 4: maxProd = max(4, -3 * 4) = max(4, -12) = 4; minProd = min(4, -6 * 4) = min(4, -24) = -24
maxProd=4, minProd=-24, result=2
Why: Update max and min products with current element
Step 6: Update result = max(2, 4) = 4
result=4
Why: Update maximum product found
Step 7: Process -1: swap maxProd and minProd because -1 is negative
Before swap: maxProd=4, minProd=-24
After swap: maxProd=-24, minProd=4
Why: Negative flips max and min, so swap
Step 8: Update maxProd = max(-1, -24 * -1) = max(-1, 24) = 24; minProd = min(-1, 4 * -1) = min(-1, -4) = -4
maxProd=24, minProd=-4, result=4
Why: Calculate new max and min products including current element
Step 9: Update result = max(4, 24) = 24
result=24
Why: Update maximum product found
Step 10: Process 0: maxProd = max(0, 24 * 0) = 0; minProd = min(0, -4 * 0) = 0
maxProd=0, minProd=0, result=24
Why: Zero resets product, start fresh from next element
Step 11: Update result = max(24, 0) = 24
result=24
Why: Maximum product remains unchanged
Step 12: Process 5: maxProd = max(5, 0 * 5) = 5; minProd = min(5, 0 * 5) = 0
maxProd=5, minProd=0, result=24
Why: Start new product subarray from 5
Step 13: Update result = max(24, 5) = 24
result=24
Why: Maximum product remains 24
Result: Maximum product subarray = 24