Skip to content

Commit 7b9abc1

Browse files
committed
Add prompt for LC 1413
1 parent 24275fa commit 7b9abc1

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
3+
1413. Minimum Value to Get Positive Step by Step Sum
4+
5+
Given an array of integers nums, you start with an initial positive value startValue.
6+
7+
In each iteration, you calculate the step by step sum of startValue plus elements in nums (from left to right).
8+
9+
Return the minimum positive value of startValue such that the step by step sum is never less than 1.
10+
11+
12+
Example 1:
13+
Input: nums = [-3,2,-3,4,2]
14+
Output: 5
15+
16+
Explanation: If you choose startValue = 4, in the third iteration your step by step sum is less than 1.
17+
step by step sum
18+
startValue = 4 | startValue = 5 | nums
19+
(4 -3 ) = 1 | (5 -3 ) = 2 | -3
20+
(1 +2 ) = 3 | (2 +2 ) = 4 | 2
21+
(3 -3 ) = 0 | (4 -3 ) = 1 | -3
22+
(0 +4 ) = 4 | (1 +4 ) = 5 | 4
23+
(4 +2 ) = 6 | (5 +2 ) = 7 | 2
24+
25+
Example 2:
26+
Input: nums = [1,2]
27+
Output: 1
28+
Explanation: Minimum start value should be positive.
29+
30+
Example 3:
31+
Input: nums = [1,-2,-3]
32+
Output: 5
33+
34+
35+
Constraints:
36+
1 <= nums.length <= 100
37+
-100 <= nums[i] <= 100
38+
39+
*/
40+
41+
/**
42+
* @param {number[]} nums
43+
* @return {number}
44+
*/
45+
const minStartValue = (nums) => {};

0 commit comments

Comments
 (0)