Find an Equal-Sum Split
Problem statement
Given an integer array nums, determine whether one boundary can divide it into two contiguous, nonempty subarrays with equal sums. Every element must belong to exactly one of the two subarrays.
Return true when such a boundary exists. Otherwise, return false.
Function
canSplitEqualSum(nums: int[]) → booleanExamples
Example 1
nums = [1,2,3,6]return = trueSplit after the first three elements. The sums of [1,2,3] and [6] are both 6.
Example 2
nums = [1,2,4]return = falseNeither valid boundary gives equal left and right sums.
Example 3
nums = [0,0,0]return = trueSplitting after the first element gives two nonempty parts whose sums are both 0.
Example 4
nums = [2,-2,5,0,5]return = trueThe contiguous parts [2,-2,5] and [0,5] both sum to 5.
Constraints
2 <= nums.length <= 2 * 10^5.-10^9 <= nums[i] <= 10^9.- Every prefix sum and the total sum fit in a signed 64-bit integer.