Skip to content

Latest commit

 

History

History
28 lines (21 loc) · 2.09 KB

File metadata and controls

28 lines (21 loc) · 2.09 KB

Maximum Product Subarray medium #javascript #blind75 #dynamic-programming #array

by Pawan Kumar @jsartisan

Take the Challenge

Given an integer array nums, find the contiguous subarray with the largest product and return the product.

Rules:

  • Subarray must be contiguous (elements next to each other)
  • Subarray must be non-empty
  • Result will fit in 32-bit integer

Constraints:

  • 1 ≤ nums.length ≤ 1000
  • -10 ≤ nums[i] ≤ 10

Examples:

// Example 1:
console.log(maxProduct([1,2,-3,4]));
// Output: 4
// Explanation: [4] has largest product

// Example 2:
console.log(maxProduct([-2,-1]));
// Output: 2
// Explanation: [-2,-1] product is 2

Back Share your Solutions Check out Solutions