Find max consecutive 1s if you can flip at most one 0.

Input: nums=[1,0,1,1,0] → Output: 4 Input: nums=[1,0,1,1,0,1] → Output: 4

Sliding window tracking number of zeros flipped (at most 1).

public int findMaxConsecutiveOnes(int[] nums) { int left = 0, zeros = 0, max = 0; for (int right = 0; right < nums.length; right++) { if (nums[right] == 0) zeros++; while (zeros > 1) { if (nums[left++] == 0) zeros--; } max = Math.max(max, right - left + 1); } return max; }