Kadane's Algorithm
Kadane's Algorithm finds the maximum sum of a contiguous subarray in a single pass. At each position, we decide whether it is better to extend the current subarray or start a new subarray at the current element.
Time complexity: O(n).
Auxiliary space: O(1).
The algorithm works with negative values when initialized correctly.
The decision is based on whether extending the previous subarray improves the current sum.
The algorithm can be extended to track the actual start and end indexes of the best subarray.