53. Maximum Subarray
Last updated
Last updated
See description at
See . This is a slight modification of Kadane's algorithm in that it allows for an input array of all negatives (example: nums = [-5, -3, -7, -2, -4]. The result in this case will be -3. The input array is also assumed to have at least one value.
I was on the right track to the optimal solution which is Kadane's Algorithm. I should have taken extra time to look at my nested if statements. I knew it was bad, but just submitted anyway. If I stopped and looked closer, I think I could have simplified it closer to Kadane's Algorithm. I was happy I found the O(N) solution.