Skip to main content
Back to problems
Leetcode
Medium
Arrays
Number Of Ways To Split Array

Count the split points where the left part has a sum at least as large as the right part.

Acceptance 63%
Problem Statement

Given an integer array nums, count how many indices i can be chosen so that splitting the array into nums[0..i] and nums[i+1..n-1] produces a left sum that is greater than or equal to the right sum.

A split is valid only when both parts are non-empty.

Input Format

  • A single integer array nums.
  • You may assume the array is represented in the standard interview format for an integer list.

Output Format

Return the number of valid split indices.

Constraints

  • The array has at least 2 elements.
  • Elements may be positive, negative, or zero.
  • Use 64-bit arithmetic if needed when summing values.
Examples
Sample cases returned by the problem API.

Example 1

Input

nums = [10, 4, -8, 7]

Output

2

Explanation

Valid splits are after index 0 and after index 1.

  • Left = [10], Right = [4, -8, 7] => 10 >= 3
  • Left = [10, 4], Right = [-8, 7] => 14 >= -1 Splits after index 2 and the end are not allowed or not valid.

Example 2

Input

nums = [2, 3, 1, 0]

Output

2

Explanation

Valid splits are after index 1 and after index 2.

  • [2, 3] vs [1, 0] => 5 >= 1
  • [2, 3, 1] vs [0] => 6 >= 0

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.