FunctionRacerProblemsRace

Longest Ones After Deleting One

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

nums holds only 0s and 1s. You must delete exactly one item. Then look for the longest unbroken run of 1s in what is left, and return its length.

If nums has no 0 you still delete one item (a 1).

Example 1

nums [1,1,0,1]
returns 3

Delete the 0 to get [1, 1, 1], so 3.

Example 2

nums [1,1,1]
returns 2

You must delete a 1, leaving two.

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