Problem
First Balanced Removal Index
You are given an integer array nums. Choose exactly one index and remove the element at that index. After removal, the remaining elements shift left to close the gap.
An index is balanced if, after removing that element, the sum of values at even positions is equal to the sum of values at odd positions.
Return the first balanced index. If no such index exists, return -1.
Positions are zero-indexed.
Examples
01 · Example 1
nums = [2, 1, 6, 4] return = 1
Remove nums[1]. The remaining array is [2,6,4]. The even-position sum is 2 + 4 = 6, and the odd-position sum is 6.
02 · Example 2
nums = [1, 1, 1] return = 0
Removing index 0 leaves [1,1], whose even and odd sums are both 1. This is the first valid index.
Constraints
1 <= nums.lengthnums[i]is an integer.
More Oracle problems
public int firstBalancedRemovalIndex(int[] nums) {
// write your code here
}nums[2, 1, 6, 4]
expected1
sign in to submit