About Shipping
A shop has n item types. The quantity of the i-th item type is quantity[i], using 1-based indexing in the description.
The items must be shipped in two consecutive consignments split by an index j: the first consignment contains item types [1, 2, ..., j], and the second contains item types [j + 1, ..., n]. Choose j such that 1 <= j < n, so both consignments are non-empty.
In one operation, increase or decrease any quantity[i] by 1. Quantities must remain positive. Return the minimum number of operations needed to make the total quantities in the two consignments equal, choosing the split optimally.
1Example 1
Increase quantity[3] by 1 to get [1, 4, 5]. Splitting at j = 2 gives consignments with sums 5 and 5, so the answer is 1.
2Example 2
The only split already has equal sums, so no operation is needed.
Constraints
Limits and guarantees your solution can rely on.
2 <= quantity.length1 <= quantity[i]- The return value may exceed the 32-bit integer range.