Problem 387146 · easy · Phase 03 Linear Management & Searching

Front-Heavy Cuts

prefix sums · counting · splits

Seed packets are lined up with weights weights. A cut after position i (with 0 <= i < n - 1) splits the line into a front part weights[0..i] and a back part weights[i+1..n-1], both non-empty. Count the cuts where the front part weighs at least as much as the back part.

Examples

Input:  weights = [10, 4, -8, 7]
Output: 2
Explanation: cut after index 0: 10 >= 3; after index 1: 14 >= -1; after index 2: 6 >= 7 fails.

Input:  weights = [1]
Output: 0
Explanation: no cut leaves both parts non-empty.

Constraints

  • 1 <= len(weights) <= 10**5
  • -10**5 <= weights[i] <= 10**5
  • Target complexity: O(n) time, O(1) extra space.

Goals

  • Evaluate every split point with a running left total
  • Derive the right total from the grand total
Starting Python…