Trains the technique from
LeetCode 1664Ways to Make a Fair ArrayThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A strip of readings reads readings. Removing exactly one reading closes the gap behind it, so everything after it shifts one place along.
A strip is balanced when the readings at even positions add up to the same as the readings at odd positions, counting positions from zero.
Return how many single removals leave the strip balanced.
Example 1
Removing the only reading leaves nothing at all, so both totals are nothing and the strip is balanced.
Example 2
Either removal leaves one reading at an even position, so the even total is five against nothing.
Example 3
Removing the first reading leaves 2, 1, 2 with an even total of four against an odd total of one, and so on for the others; only one of the four removals balances.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def ways_to_make_fair(readings: list[int]) -> int:public int waysToMakeFair(int[] readings)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.