Lowest Start That Keeps Running Totals Positive
Updated
Problem statement
You pick a whole number x to start with. Then you add the numbers of the array arr to it one at a time, from left to right. After each addition you have a running total.
Return the smallest x such that:
xitself is at least1, and- every running total
x + arr[0] + ... + arr[i]is at least1.
Function
minStart(arr: int[]) → intExamples
Example 1
arr = [-2,5,-6,1]return = 4Try x = 4. The running totals are 4 - 2 = 2, 2 + 5 = 7, 7 - 6 = 1 and 1 + 1 = 2. All of them are at least 1.
With x = 3 the third total would be 3 - 2 + 5 - 6 = 0, which is too small. So the answer is 4.
Example 2
arr = [2,3,1]return = 1Every number is positive, so the totals only go up. The smallest allowed start, x = 1, already works: the totals are 3, 6 and 7.
Example 3
arr = [-7]return = 8The only total is x - 7. It is at least 1 when x is at least 8.
Constraints
1 <= arr.length <= 1000-10^6 <= arr[i] <= 10^6
More DocuSign Online Assessment questions
- Max Sum With No Two Adjacent PicksOA · Seen Apr 2026
- Max Sum With No Two Adjacent Picks on a CircleOA · Seen Apr 2026
- Beautiful Number OrderingsOA · Seen Feb 2026
- Grid Path With the Most ClearanceOA · Seen May 2025
- Vehicle Mixes for a Wheel TotalOA · Seen May 2025
- Count Sales Rung Up at the Wrong PriceOA · Seen Feb 2021
- Most Disjoint Intervals From Starts and DurationsOA · Seen Feb 2021
- Fewest Fountains to Water the GardenOA · Seen Feb 2021
- Fewest Student Groups Within a Level GapOA · Seen Nov 2020
- Alphabetize a Word ListOA · Seen May 2020
Similar questions at other companies
- Minimum Positive Starting ValueBooking.com · OA
- Array Interval SumsHeadlands Technologies · OAHeadlands Technologies interview questions
- Minimum AmountBelvedere Trading · OA
- Online No-Intercept Linear RegressionTwo Sigma · OATwo Sigma interview questions
- Range Sum QueriesIntuit · OAIntuit interview questions
- Shortest Distance on a Circular Bus RouteAmazon · OA
- Count Sortable SplitsGoogle · OAGoogle interview questions
- Array Challenge (QR Intern)Akuna Capital · OAAkuna Capital interview questions
- Range Negation UpdatesJP Morgan Chase · OAJP Morgan Chase interview questions
- Threshold AlertsGoldman Sachs · OAGoldman Sachs interview questions