First Balanced Removal Index
Reported by candidates from Oracle's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Remove one element, let everything shift left, then check if even-position and odd-position sums match. That's the Oracle problem reported in December 2025, and the shift is what trips people up. The brute force is obvious and too slow at 10^5 elements. The real answer is prefix sums split by index parity, which turns each removal check into O(1). If you blank on the parity swap during the live OA, StealthCoder runs invisibly on your desktop and gives you the working solution as a safety net. Still, the idea is small enough to own before you sit down.
The problem
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[]) → int Examples 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. 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.length <= 105 -106 <= nums[i] <= 106
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: when you remove index i, everything before i keeps its parity. Everything after i flips parity, since it shifts left by one. So precompute prefix sums of even-indexed and odd-indexed values. For index i, new even sum = evenBefore(i) + oddAfter(i). New odd sum = oddBefore(i) + evenAfter(i). Compare them, return the first i that matches, else -1. That's O(n) time and O(1) extra space if you track running totals against total even and odd sums. The common pitfall is forgetting the flip and just subtracting nums[i] from its own parity bucket. Another is off-by-one on whether 'after' includes i. It doesn't. Negative values are allowed, so don't use early-exit logic that assumes sums only grow. Check example 2 by hand: removing index 0 from [1,1,1] leaves [1,1], balanced. If the live OA freezes you, StealthCoder is your hedge for the syntax and edge cases.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill First Balanced Removal Index cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as ways to make a fair array. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Oracle's OA.
Oracle reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
First Balanced Removal Index FAQ
What's the trick in First Balanced Removal Index?+
Parity flips for every element after the removed index. Keep prefix sums of even and odd positions. New even sum is evenBefore plus oddAfter, new odd sum is oddBefore plus evenAfter. Compare in O(1) per index and return the first match.
How hard is this Oracle OA question really?+
Medium. The brute force is easy to write but times out at 10^5 elements. The only real hurdle is seeing the parity flip. Once you see it, the code is about 15 lines with one pass over the array.
What time complexity does the OA expect?+
Aim for O(n) time. With n up to 10^5, an O(n^2) rebuild-and-sum approach is too slow. You can do it with O(1) extra space by keeping running even and odd totals instead of full prefix arrays.
What edge cases should I test?+
Test a single-element array, since removing it leaves an empty array with both sums at zero, so it returns 0. Test negative values, an array with no balanced index returning -1, and cases where the first valid index is the last one.
How do I prepare for this in 48 hours?+
Write the solution once from scratch using prefix sums by parity. Then hand-trace both examples. Practice a couple of similar parity and prefix sum problems so the flip after removal feels automatic. Don't memorize code, memorize the formula.