class Solution:
def longestOnes(self, A: List[int], K: int) -> int:
#TC: O(n)
#SC: O(1)
#Use simple two pointers and sliding window
count = 0
left = 0
right = 0
res = 0
n = len(A)
while right < n:
if A[right] == 0:
if count < K:
count += 1
else:
while left <= right:
if A[left] == 0:
left += 1
break
left += 1
L = right - left + 1
res = max(res, L)
right += 1
return res