diff --git a/leetcode/stuff.py b/leetcode/stuff.py index 5164abc..768f0bb 100644 --- a/leetcode/stuff.py +++ b/leetcode/stuff.py @@ -550,6 +550,19 @@ def sum_max_sub_array(nums: list[int]) -> int: return mmax +def sum_max_sub_array_i(nums: list[int]) -> tuple[int, int]: + mmax_i: int = 0 + mmax = last = prev = nums[0] + + for i in range(1, len(nums)): + prev = nums[i] + last + last = max(nums[i], prev) + mmax_i = i if last > mmax else mmax_i + mmax = max(mmax, last) + + return mmax_i, mmax + + def sum_max_sub_array_accum(nums: list[int]) -> int: accum: list[int] = [nums[0]]