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
- Discussions
The Maximum Subarray
The Maximum Subarray
Sort by
recency
|
40 Discussions
|
Please Login in order to post a comment
Java 8 Solution:-
Here is - HackerRank The Maximum Subarrray problem solution in Python, Java, C++, C and javascript
Kadane's max subArray sum
js solution, use Kadane's algorithm for the subarray sum, however seems failing the one long test
You didn't specify an initial value for the reduce function, so the initial value will be the first value of the array. That would mess things up.
Imagine arr = [-10, 2, 4, 5]
maxSeq should be 2 + 4 + 5 = 11
But since you didnt' specify it, so it ended being like this initial value = -10, then based on logic if (curr >0) -10 + 2, then + 4, then + 5. Instead of 0 +2, then +4 then +5. Total would be 1 Do you see the issue?