<commit_before># 152. Maximum Product Subarray (Medium)

Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product.

### Example 1:
```
Input: [2,3,-2,4]
Output: 6
Explanation: [2,3] has the largest product 6.
```
### Example 2:
```
Input: [-2,0,-1]
Output: 0
Explanation: The result cannot be 2, because [-2,-1] is not a subarray.
```

## Solution
### Intuitive Approach
Brutally try all the subarray, O(N^2) i = [0..N], j = [i..N]

### Optimal O(N) Approach
A very elegant solution from programming pearls:

calculating local min and local max, then swap them because multiplying by a negative makes big number smaller, small number bigger so we redefine the extremums by swapping them.<commit_msg>README.md<commit_after># 152. Maximum Product Subarray (Medium)

Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product.

### Example 1:
```
Input: [2,3,-2,4]
Output: 6
Explanation: [2,3] has the largest product 6.
```
### Example 2:
```
Input: [-2,0,-1]
Output: 0
Explanation: The result cannot be 2, because [-2,-1] is not a subarray.
```

## Solution
### Intuitive Approach
Brutally try all the subarray, O(N^2) i = [0..N], j = [i..N]

### Optimal O(N) Approach
A very elegant solution from programming pearls:

- Calculating local min and local max of between each element and min/max
- Swap them because multiplying by a negative makes big number smaller, small number bigger so we redefine the extremums by swapping them.
{'fraction_non_alphanumeric': 0.11397984886649874, 'fraction_numerical': 0.027707808564231738, 'mean_word_length': 4.441780821917808, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6151290', 'n_tokens_mistral': 527, 'n_tokens_neox': 474, 'n_words': 228}