#137 Maximum Subarray of Ones After Deleting One Element
Given an array containing zeros and ones, determine the maximum length of a subarray of ones that can be obtained by deleting exactly one array element.
Return 0 if no such subarray exists. Deleting one element is mandatory.
Example:
[1, 1, 0, 1, 1, 1]
Deleting the 0 at position 2 produces a subarray of length 5: [1, 1, 1, 1, 1]
Answer: 5
[1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1]
Deleting the second 0 at position 6 produces the maximum subarray
[1, 1, 1, 1, 1, 1, 1, 1, 1] of length 9.
Answer: 9Question review
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor