Skip to interview prep
Apexed
Problem list106 / 125

106. Maximum Product Subarray

MediumDynamic programming

Return the largest product of any non-empty contiguous subarray of the integers nums.

Example 1

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

Example 2

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

Constraints

  • 1 ≤ nums.length ≤ 2 · 10⁴
  • -10 ≤ nums[i] ≤ 10
  • The answer fits in a 32-bit integer

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 5 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Maximum Product Subarray — coding interview practice — Apexed