0 out of 464 challenges solved
Write a Python function `max_sub_array_sum(arr)` that takes a list of integers `arr` as input and returns the sum of the largest contiguous sublist within the list. A contiguous sublist is a sequence of elements that are adjacent in the list. #### Example Usage ```python [main.nopy] print(max_sub_array_sum([-2, -3, 4, -1, -2, 1, 5, -3])) # Output: 7 print(max_sub_array_sum([1, 2, 3, -2, 5])) # Output: 9 print(max_sub_array_sum([-1, -2, -3, -4])) # Output: 0 ``` #### Constraints - The input list can contain both positive and negative integers. - The function should return `0` if all elements in the list are negative. - The input list will have at least one element.
def max_sub_array_sum(arr): """ Find the sum of the largest contiguous sublist in the given list. Args: arr (list): A list of integers. Returns: int: The sum of the largest contiguous sublist. """ # Initialize variables to track the maximum sum and current sum # Implement the logic to find the maximum sum of a contiguous sublist pass