FreeCareerPath
Build the PrimitiveMedium

Maximum Product Subarray

Write `max_product(nums)` returning the largest product of any contiguous non-empty subarray. max_product([2,3,-2,4]) -> 6 max_product([-2,0,-1]) -> 0 Kadane on sums does not transfer directly: multiplying by a negative turns the smallest running product into the largest. So carry both, and swap them when the current value is negative. Zero resets both.

What to expect: A timer starts when you begin. Edit the starter code, run it against the test suite as many times as you like, then finish when you're done. The reference solution and interviewer follow-up questions unlock only after you finish.

Log in to start this session

Timed sessions and your results for "Maximum Product Subarray" are saved to your account — logging in takes a few seconds.

Maximum Product Subarray — FreeCareerPath