Reported September 2026
ByteDanceprefix sum

Delete K Values to Balance Index Sums

Reported by candidates from ByteDance's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live ByteDance OA. Under 2s to a working solution.
Founder's read

The data structure that carries this ByteDance OA from September 2026 is a pair of prefix sum arrays, one for even indices and one for odd. You're deleting a block of k values, and everything after the block shifts left by k, which can flip parity. That's the whole problem. If you try to rebuild the array for every start index, you'll time out at 100000 elements. Prefix sums by parity make each check O(1). StealthCoder is the safety net if you blank mid-assessment, but the idea is short enough to hold in your head tonight.

The problem

You are given an integer array nums and an integer k. Delete exactly one contiguous block of k values.
After deletion, the remaining values close the gap and receive new zero-based indices. Find the smallest start index of a block whose deletion makes the sum at even indices equal the sum at odd indices.
Return that smallest start index, or -1 when no block works.

Function
firstBalancedBlock(nums: int[], k: int) → int

Examples
Example 1
nums = [2,1,6,4]
k = 1
return = 1
Deleting nums[1] leaves [2,6,4]. Its even-index sum is 2 + 4 = 6, equal to its odd-index sum 6.
Example 2
nums = [1,2,3]
k = 1
return = -1
No single-value deletion balances the two index-parity sums.

Constraints
1 <= nums.length <= 100000
1 <= k <= nums.length
-10^9 <= nums[i] <= 10^9

Reported by candidates. Source: FastPrep

Pattern and pitfall

Build two prefix arrays: E[i] is the sum of nums at even original indices before i, O[i] is the same for odd. For a block starting at s covering s to s+k-1, the prefix part keeps its parity. The suffix part starting at s+k lands at index (original - k). If k is even, parity stays the same. If k is odd, parity flips for the suffix. So the new even sum is E[s] + (suffix even sum or suffix odd sum depending on k's parity), and the odd sum works the same way. Compare the two and return the first s from 0 to n-k that matches. Pitfalls: forgetting the parity flip when k is odd, off-by-one on the suffix start, and overflow. Values reach 10^9 across 100000 items, so use 64-bit. Negative values rule out any greedy or two-pointer shortcut. The scan is O(n) total. If you freeze in the live OA, StealthCoder can hand you the indexing, but know the flip rule yourself.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Delete K Values to Balance Index Sums 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 StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass ByteDance's OA.

ByteDance 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.

Delete K Values to Balance Index Sums FAQ

What's the trick in Delete K Values to Balance Index Sums?+

Precompute prefix sums separately for even and odd original indices. After deleting a block, the suffix shifts left by k. If k is odd, even and odd roles swap for the suffix. Combine prefix and suffix sums in O(1) per start index and return the first match.

How hard is this ByteDance OA problem really?+

Medium. The idea is simple once you see the parity flip, but the indexing is easy to botch. With n up to 100000, brute force rebuilding fails, so you need the O(n) prefix approach. Most of the difficulty is off-by-one errors, not the algorithm.

Why does odd k flip the parity of the suffix?+

An element at original index j ends up at j - k. If k is even, j and j - k share parity. If k is odd, they differ. So elements that were at even positions after the block now sit at odd positions, and vice versa.

Do I need 64-bit integers here?+

Yes. Each value can be up to 10^9 in magnitude and there can be 100000 of them, so sums can reach about 10^14. A 32-bit int overflows. Use long in Java or C++, Python handles it natively.

How do I prepare for this in 48 hours?+

Write the solution once from scratch using prefix sums by parity. Test it on both examples, then on k equal to n and k equal to 1. Check the edge where the whole array is deleted, leaving zero on both sides. That covers nearly every bug you'd hit.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with ByteDance.

OA at ByteDance?
Invisible during screen share
Get it