Goldman SachsOA #25
Minimum Start Value
Estimated EasyJudge-ready
Topics (AI-labelled)Prefix & Ranges
Given an integer array, find the smallest positive initial value x such that, when the elements are added from left to right, every prefix sum is at least 1.
Input
The first line contains n (1..100000); the second line contains n integers arr[i] (−10^6..10^6).
Output
Output the smallest valid initial value x.
Example 1
Input:
10
-5 4 -2 3 1 -1 -6 -1 0 5
Output:
8
Example 2
Input:
5
-5 4 -2 3 1
Output:
6
Example 3
Input:
3
1 2 3
Output:
1
Editorial
Loading solution…