---
# System prepended metadata

title: Untitled

---

Find the contiguous subarray within an array (containing at least one number) which has the largest sum.

For example, given the array [-2,1,-3,4,-1,2,1,-5,4],
the contiguous subarray [4,-1,2,1] has the largest sum = 6.
        
```python        
def large_sum(array):
    result = -inf
    for i in range(len(array)):
        temp = array[i]
        for j in range(i, len(array)):
            temp += array[j]
            result = result > temp if result else temp
    return sum

def large_sum(array):
    result = array[0]
    for i in range(1, len(array)):
        temp = array[i]
        if temp > result:
            result = temp
        else:
            temp += result
            if temp > result:
                result = temp
            
```