Max Consecutive Ones III
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 are given a binary array nums (every element is either 0 or 1) and an integer k.
You are allowed to flip at most k zeros into ones. After performing these flips, return the length of the **longest contiguous run** of 1s that can be obtained.
In other words, find the maximum length of a subarray that contains **at most k zeros** — those zeros can all be flipped to 1, producing an unbroken block of ones of that length.
If no flips are needed (or k is large enough to cover every zero in a window), the answer is simply the length of the best such window.
Examples
Constraints
- 1 <= nums.length <= 10^5
- nums[i] is either 0 or 1
- 0 <= k <= nums.length
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.