We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The Maximum Subarray
The Maximum Subarray
Sort by
recency
|
491 Discussions
|
Please Login in order to post a comment
java8
O(n)
java 8 beginner way
int sum=0;
}
I'm going to exlain my approach for the "find max sub array" part of this problem.:
Let's say you have a sub-array, initially it's empty. For any item in the original array, you basically have 2 choices: 1. Add this item to the current sub-array. 2. Make a new sub-array starting from this item.
With dynamic programming, you can keep tracking the max-sum of the sub-array for both of the choices you've made at each item in the original array.
PHP code for this approach: