Problem
First Balanced Removal Index
Learn this problemProblem statement
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.
Function
firstBalancedRemovalIndex(nums: int[]) → intExamples
Example 1
nums = [2, 1, 6, 4]return = 1Remove nums[1]. The remaining array is [2,6,4]. The even-position sum is 2 + 4 = 6, and the odd-position sum is 6.
Example 2
nums = [1, 1, 1]return = 0Removing index 0 leaves [1,1], whose even and odd sums are both 1. This is the first valid index.
Constraints
1 <= nums.length <= 105-106 <= nums[i] <= 106
More Oracle problems
- Alphabetically Maximum SubstringPHONE SCREEN · Seen Jul 2026
- Best Time to Buy and Sell StockPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Enumerate Right-and-Down Matrix PathsONSITE INTERVIEW · Seen Jul 2026
- Maximize Movie Ratings Without Consecutive SkipsONSITE INTERVIEW · Seen Jul 2026
- Add One to a Number Represented as DigitsONSITE INTERVIEW · Seen Jul 2026
- Top K Frequent Elements with Larger-Value Tie BreakONSITE INTERVIEW · Seen Jul 2026
- Merge k Sorted ListsPHONE SCREEN · Seen Jul 2026
- Implement a Queue Using Two StacksPHONE SCREEN · Seen Jul 2026