Skip to main content
LeetCode 2270, Medium. Topics: Array, Prefix Sum. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 20 parametrized pytest cases, and a playground notebook:

Problem

You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>. <p><code>nums</code> contains a <strong>valid split</strong> at index <code>i</code> if the following are true:</p> <ul> <li>The sum of the first <code>i + 1</code> elements is <strong>greater than or equal to</strong> the sum of the last <code>n - i - 1</code> elements.</li> <li>There is <strong>at least one</strong> element to the right of <code>i</code>. That is, <code>0 <= i < n - 1</code>.</li> </ul> <p>Return <em>the number of <strong>valid splits</strong> in</em> <code>nums</code>.</p>

Examples

Constraints

  • 2 <= nums.length <= 10^5
  • -10^5 <= nums[i] <= 10^5

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

NeetCode All.
Last modified on September 7, 2026