1413. Minimum Value to Get Positive Step by Step Sum
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 65% Topics: Array, Prefix Sum
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(1)
class Solution(object):
def minStartValue(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
min_prefix, prefix = 0, 0
for num in nums:
prefix += num
min_prefix = min(min_prefix, prefix)
return 1-min_prefix
Solution from kamyu104/LeetCode-Solutions · MIT