Approach Summary
Sliding window allowing at most one 0. Shrink left when zeros > 1. Answer is window size minus 1 (the deleted element).
How to Recognize This Pattern
- "Longest 1s after removing exactly one element"
- Window of at most one 0, subtract 1 from result
Complexity Analysis
Time Complexity
O(n)
Space Complexity
O(1)
Tags
Array Dynamic Programming Sliding Window