Back to problems

Remove Exactly One Element to Make a Pivot Index Exist

Algorithm · Google · Medium

Given an integer array nums, whose entries can be duplicated or negative, delete one and only one element by choosing an index. The resulting sequence is shorter by one, and every retained value remains in its original relative position. For an array arr, position p qualifies as a pivot index precisely when: sum(arr[0..p-1]) == sum(arr[p+1..end]) That is, the values before p must total the same as the values after p; the value at arr[p] contributes to neither total. Return…

Checking your access…