FunctionRacerProblemsRace

Max Consecutive Ones With Flips

MediumTwo pointersPython, JavaScript, TypeScript, Java, C++

nums holds only 0s and 1s. You may flip at most k of the 0s into 1s. Return the length of the longest unbroken run of 1s you can create.

Example 1

nums [1,1,1,0,0,0,1,1,1,1,0]
k 2
returns 6

Flip the 0s at indices 5 and 10: indices 5 to 10 are all 1s, a run of 6.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Two pointers problems