Trains the technique from
LeetCode 995Minimum Number of K Consecutive Bit FlipsThis 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 row of switches holds only 0 and 1. One move picks exactly k neighbouring switches and flips every one of them, so each 0 becomes a 1 and each 1 becomes a 0.
Return the fewest moves that leave every switch showing 1, or -1 when no number of moves can do it.
Example 1
Flip the first two switches and then the last two.
Example 2
Only one window exists and it covers both switches, so flipping it turns the 1 off while turning the 0 on, and the row can never come out all ones.
Example 3
A window of one switch flips a single switch, so each of the three zeros costs its own move.
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 min_k_bit_flips(switches: list[int], k: int) -> int:public int minKBitFlips(int[] switches, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.