Concept Flow - Maximum Product Subarray
Start at index 0
Initialize maxProd, minProd, result
For each element in array
If element < 0, swap maxProd and minProd
Update maxProd = max(element, maxProd * element)
Update minProd = min(element, minProd * element)
Update result = max(result, maxProd)
Move to next element
End of array?
No→Repeat loop
Yes
Return result
We scan the array once, tracking the maximum and minimum products ending at each position, swapping when negative numbers appear, and keep the highest product found.
