1413. Minimum Value to Get Positive Step by Step Sum ¶ Time: $O(n)$ Space: $O(1)$ C++JavaPython 1 2 3 4 5 6 7 8 9 10 11 12class Solution { public: int minStartValue(vector<int>& nums) { int sum = 0; int minSum = 0; for (const int num : nums) minSum = min(minSum, sum += num); return 1 - minSum; } }; 1 2 3 4 5 6 7 8 9 10 11class Solution { public int minStartValue(int[] nums) { int sum = 0; int minSum = 0; for (final int num : nums) minSum = Math.min(minSum, sum += num); return 1 - minSum; } } 1 2 3 4 5 6 7 8 9 10class Solution: def minStartValue(self, nums: list[int]) -> int: summ = 0 minSum = 0 for num in nums: summ += num minSum = min(minSum, summ) return 1 - minSum