JPMorgan ChaseOA #3
Equalize Consignment Quantities
Estimated EasyJudge-ready
Topics (AI-labelled)Prefix & Ranges
Cut once between adjacent categories to form two non-empty contiguous shipments; one operation adds one to or subtracts one from the quantity of any category, but every quantity must stay positive. Find the minimum number of operations to make the two shipments' totals equal.
Input
The first line contains n, followed by n values of quantity. 2≤n≤300000, 1≤quantity[i]≤2000000000.
Output
Output a single integer answer.
Example 1
Input:
3
1 4 4
Output:
1
Example 2
Input:
5
3 3 6 3 9
Output:
0
Example 3
Input:
3
4 5 7
Output:
2
Example notes
The outputs of the three public examples are, in order: 1; 0; 2. These answers have been checked by independent enumeration or direct simulation.
Editorial
Loading solution…