← All problems

Maximum Product Subarray

Medium dynamic programmingarrays LeetCode ↗
Given an integer array, find the contiguous subarray with the largest product and return that product. Negative numbers make this trickier than the maximum-sum variant.

Hints (0/3 revealed)

Log in to reveal hints progressively.

Complexity

Time O(n), Space O(1)

Common pitfalls

  • Only tracking max (sign flips break it)
  • Zero-reset mistakes

Your solution

Log in to save your code and track progress.