Problem statement

https://binarysearch.com/problems/Largest-Sublist-Sum/

Solution

Equal to Leetcode 0053. Maximum Subarray

Complexity

It is O(n) for time and space.

Code

class Solution:
    def solve(self, nums):
        dp = [0]*len(nums)
        dp[0] = nums[0]
        for i in range(1, len(nums)):
            dp[i] = max(nums[i], nums[i] + dp[i-1])
        return max(dp)