#137 Maximum Subarray of Ones After Deleting One Element

Companies:
VK Yandex
Themes:
AlgorithmsArraysPractice

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.

Text
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: 9

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in