FastPrepFastPrep
Problem Brief

About Shipping

INTERNOA

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

Input
quantity = [1, 4, 4]
Output
1
Explanation

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

Input
quantity = [2, 2]
Output
0
Explanation

The only split already has equal sums, so no operation is needed.

Constraints

Limits and guarantees your solution can rely on.

  • 2 <= quantity.length
  • 1 <= quantity[i]
  • The return value may exceed the 32-bit integer range.
public long getMinimumOperations(int[] quantity) {
  // write your code here
}
Input

quantity

[1, 4, 4]

Output

1

Sign in to submit your solution.

Company OA Practice

About Shipping for JPMorgan Chase online assessment prep

FastPrep catalogs About Shipping as a JPMorgan Chase coding interview and online assessment practice problem. Review the prompt, examples, constraints, and nearby company problems together so the preparation context stays focused on JPMorgan Chase OA patterns.