Maximum Product Subarray

Medium · Dynamic Programming · Array · Dynamic Programming

Problem

Find the contiguous subarray with the largest product and return that product.

The array is non-empty and every product fits in a 32-bit integer.

Examples

Input: nums = [2,3,-2,4]
Output: 6

The subarray [2,3] has product 6.

Input: nums = [-2,0,-1]
Output: 0

The best available product is 0.

Constraints

Approaches

Related problems

Start free on Cariara · Coding problems · System design studio

Starting Python
No results yet.

          
↑↓ move ↵ open esc close

Labs

Loading labs…

Run with your own input

Starting Python

Loading Python…