mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-04-20 04:37:36 +00:00
19 lines
541 B
Python
19 lines
541 B
Python
"""
|
|
Given an integer array, the task is to find the maximum product of any subarray.
|
|
Input: arr[] = {-1, -3, -10, 0, 60}
|
|
Output: 60
|
|
Explanation: The subarray with maximum product is {60}.
|
|
"""
|
|
|
|
def max_product(arr):
|
|
result = 0
|
|
|
|
for x in range(len(arr)):
|
|
current_product = 1
|
|
for y in range(x, len(arr)):
|
|
current_product *= arr[y]
|
|
result = max(result, current_product)
|
|
return result
|
|
|
|
# Test the function with the provided input
|
|
print(max_product([-1, -3, -10, 0, 60])) # Expected output: 60 |