Implementation of Kadane algorithm