Find the largest sum of consecutive integers in an array.

Given an array of integers, this function returns the largest sum of consecutive integers in the array.

Problem

Given an array of integers, write a function that returns the largest sum of consecutive integers in the array.
Example input:
[5, 10, -5, 11, 5, 20, -6]
Example output:
36

Solution

This solution is in Python. Our A.I. can create solutions in multiple languages.
by kayakane
def largest_sum(arr):
    max_sum = 0
    current_sum = 0
    for i in arr:
        current_sum += i
        if current_sum < 0:
            current_sum = 0
        if current_sum > max_sum:
            max_sum = current_sum
    return max_sum

print(largest_sum([5, 10, -5, 11, 5, 20, -6]))

A.I. Evaluation of the Solution

The candidate's solution correctly returns the largest sum of consecutive integers in the array. The approach is straightforward and easy to follow.

Evaluated at: 2022-11-25 00:16:22