def kadanes(arr: list) -> int:
    max_sum = negative_exist(arr)
    if max_sum < 0:
        return max_sum

    max_sum = 0
    max_till_element = 0

    for i in arr:
        max_till_element += i
        max_sum = max(max_sum, max_till_element)
        max_till_element = max(max_till_element, 0)
    return max_sum