Problem · Array
Pivot Index After Exactly One Removal
Learn this problemProblem statement
Given an integer array nums, remove exactly one element by index. The remaining elements keep their relative order.
A pivot index in the remaining array is an index whose strictly-left sum equals its strictly-right sum; the pivot value belongs to neither sum.
Return true if at least one removal leaves a nonempty array with a pivot index. Otherwise return false.
Function
canCreatePivot(nums: int[]) → booleanExamples
Example 1
nums = [1,2,3]return = falseRemoving any one value leaves a two-element array with unequal nonzero values. Neither index can have equal left and right sums.
Example 2
nums = [2,1,1,2,2]return = trueRemove the first 2. The remaining array is [1,1,2,2]; at pivot index 2, the left sum is 1 + 1 = 2 and the right sum is 2.
Example 3
nums = [4,1]return = trueRemoving either element leaves a one-element array. Its only index has empty left and right sides, both summing to zero.
Constraints
1 <= nums.length <= 200000-1000000000 <= nums[i] <= 1000000000- Use signed 64-bit arithmetic for sums.