LeetCode solutions

1514. Minimum Value to Get Positive Step by Step Sum

My accepted Python solution to LeetCode problem 1514, Minimum Value to Get Positive Step by Step Sum, running in 0ms.

  • Difficulty: Easy
  • Python
  • Runtime 0ms
  • Memory 17.2MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 0ms, memory 17.2MB, accepted 2025-12-29.

python
class Solution:
    def minStartValue(self, nums: List[int]) -> int:
        min_prefix = 0
        prefix_sum = 0
        for num in nums:
            prefix_sum += num
            min_prefix = min(min_prefix, prefix_sum)
        return max(1, 1 - min_prefix)

Source