Kadane's algorithm with back pointers