Maximum subarray problem: enhance code and make space complexity to O(1).