Minimum Number of K Consecutive Bit Flips
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You have a binary array nums and an integer k. In one operation you pick a window of exactly k **consecutive** elements and flip every bit in it (0 becomes 1, 1 becomes 0).
Return the **minimum** number of operations needed to make every element equal to 1, or -1 if it is impossible.
Target O(n) time: simulating each flip element by element costs O(n * k).
Examples
Constraints
- `1 <= nums.length <= 10^5`
- `1 <= k <= nums.length`
- `nums[i]` is `0` or `1`
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.