Adding max subarray algorithm with linear time