Dsa
Dynamic Programming
Easy
Maximize Subarray Product
Given an array of integers, find the maximum product of any contiguous subarray. Your solution should account for negative numbers, as they can also yield a maximum product if multiplied with other negative numbers. For example, in the array [-2, 3, -4], the maximum product is 24 from the subarray [3, -4].
Input Format:
- The first line contains an integer n (1 ≤ n ≤ 1000), the number of elements in the array.
- The second line contains n space-separated integers representing the elements of the array.
Output Format:
- Output a single integer, the maximum product of any contiguous subarray.
Example:
Input:
5
-2 0 -1 3 -4
Output:
3
Key concepts
dynamic_programmingproductarray
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now