Ctrl K

Split Parcels Between Two Couriers

Hard
You have parcels with weights weights and two couriers, the first and the second. Each parcel must go to exactly one of them. A split is **acceptable** if each courier carries a total weight of at least minimum. Return the number of acceptable splits. Two splits differ if at least one parcel goes to a different courier. The couriers are distinguishable: handing a set to the first or to the second gives different splits. The answer can be large, so return it modulo 10⁹ + 7.
Example 1
weights=[3, 1, 2], minimum=3 → 2

The total is 6, so each courier needs exactly 3. The first courier can take {3} or {1, 2}: two ways.

Example 2
weights=[4, 4, 4], minimum=5 → 0

One courier always ends up with at most one parcel, i.e. at most 4. There is no way.

Example 3
weights=[2, 2, 2, 2], minimum=3 → 6

Each courier needs at least two parcels, so the split is 2 and 2: any two of the four go to the first courier, giving 6 ways.

Constraints
  • 1 ≤ len(weights) ≤ 1000
  • 1 ≤ weights[i] ≤ 10⁹
  • 1 ≤ minimum ≤ 1000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsWater Between Walls HardBiggest Solid Panel Block HardProfit From Two Trades HardEvery Way to Space the Words HardCrossing the Cave Hard
loading Python…
Input
weights=[3, 1, 2], minimum=3
Expected
2

Run checks the first 3 tests in your browser. Submit checks all 74 tests on the server, hidden ones included.