Find an Equal-Sum Split
Updated
Problem statement
You are given an integer array nums. Can you split it at one position into two nonempty parts with equal sums? Keep the elements in their original order, and include every element in exactly one part.
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.