49 - Maximum Product Subarray - Final DP solution in Java
@Rishi Srivastava
Pseudo code:
int currMax = 1;
int currMin = 1;
for (int num : nums[]) {
int tmp = currMax * num;
currMax = MAX(num * currMax, num * currMin, num); // currMax is changed here
currMin = MIN(tmp, num * currMin, num);
result = MAX(result, currMax);
}
Time complexity: O(n)
Space complexity: O(1)
Github:
Leetcode:
- Dynamic Programming Playlist:
- Dynamic Programming Github:
- Java Serialization Playlist:
- Java Serialization Github: