shlogg · Early preview
Prashant Mishra @prashantrmishra

Largest Subarray With At Most K Zeros

Find largest subarray of consecutive ones with k zeros flipped at most. Two-pointer sliding window pattern solves this problem efficiently in O(n) time complexity.

The problem asks to find out the largest subarray of consecutive ones where k zeros can be flipped at most.
This can also be interpreted as finding the largest subarray with at most k zeros.
This can be done with the two-pointer sliding window pattern:
Find the largest subarray/substring with <condition>
Problem
Brute force approach:


class Solution {
    public int longestOnes(int[] nums, int k) {
        //This can be like finding the longest subarray with at most k zeros
        //that would mean that we have the longest subarray having only k zeros 
        //which upon flip to 1 will mak...