Skip to main content
Medium Sliding Window Medium frequency

Longest Subarray of 1's After Deleting One Element

Open on LeetCode

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

This site is free. If these guides are helping your prep, consider buying me a coffee. ☕

Support →
Buy me a coffee