Split Array with Equal Sum - Problem
Given an integer array nums of length n, return true if there is a triplet (i, j, k) which satisfies the following conditions:
0 < i,i + 1 < j,j + 1 < k < n - 1- The sum of subarrays
(0, i - 1),(i + 1, j - 1),(j + 1, k - 1)and(k + 1, n - 1)is equal.
A subarray (l, r) represents a slice of the original array starting from the element indexed l to the element indexed r.
Note: The array is split into four parts by three dividers at positions i, j, and k.
Input & Output
Example 1 — Valid Split Exists
$
Input:
nums = [1,2,1,2,1,2,1]
›
Output:
true
💡 Note:
With i=1, j=3, k=5: part1=[1] sum=1, part2=[1] sum=1, part3=[1] sum=1, part4=[1] sum=1. All sums equal 1.
Example 2 — No Valid Split
$
Input:
nums = [1,2,3,4,5,6,7]
›
Output:
false
💡 Note:
No triplet (i,j,k) can create four subarrays with equal sums from this ascending sequence.
Example 3 — Too Small Array
$
Input:
nums = [1,1,1,1]
›
Output:
false
💡 Note:
Array too small (length 4 < 7). Need at least 7 elements for valid triplet positions.
Constraints
- 7 ≤ nums.length ≤ 2000
- -106 ≤ nums[i] ≤ 106
Visualization
Tap to expand
Understanding the Visualization
1
Input Array
Array with 7+ elements to be divided
2
Find Dividers
Search for valid triplet (i, j, k)
3
Check Equality
Verify all four parts have equal sum
Key Takeaway
🎯 Key Insight: Fix the middle divider to reduce from 3D to 2D matching problem
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code