Skip to content
Discussion options

You must be logged in to vote

We need to find the longest contiguous subarray of 1's after deleting exactly one element from the given binary array. The solution involves using a sliding window technique to maintain a window that contains at most one zero. The key insight is that by allowing at most one zero in the window, we can simulate the deletion of that zero to obtain a contiguous segment of 1's. The length of this segment will be the window length minus one, accounting for the deleted element.

Approach

  1. Sliding Window Technique: We maintain a window defined by two pointers, left and right. The right pointer expands the window by moving forward, while the left pointer contracts the window if the number of zeros …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Aug 24, 2025
Maintainer Author

Answer selected by basharul-siddike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants