Kadane's Algorithm
techiedelight.com