← problems
#152

Maximum Product Subarray

MediumDynamic Programming

Given an integer array nums, find a contiguous non-empty subarray that has the largest product, and return that product.

Example

nums = [2, 3, -2, 4]   => 6    // [2, 3]
nums = [-2, 0, -1]     => 0
Implement
function MaxProduct(nums: int[]) -> int

Found a bug? Or annoyed about something in the language? Tell us.

loading editor…