public int flip0sToMaximizeConsecutive1s(int input[], int flipsAllowed) {

        int windowStart = 0;
        int countZero = 0;
        int result = 0;
        for (int i = 0 ; i < input.length; i++) {
            if (input[i] == 1) {
                result = Math.max(result, i - windowStart + 1);
            } else {
                if (countZero < flipsAllowed) {
                    countZero++;
                    result = Math.max(result, i - windowStart + 1);
                } else {
                    while(true) {
                        if (input[windowStart] == 0) {
                            windowStart++;
                            break;
                        }
                        windowStart++;
                    }
                }
            }
        }
        return result;
    }
Date 12/29/2015
@author Tushar Roy

Given input array of 0s and 1s and number of flips allowed from 0 to 1, what is maximum consecutive 1s we can have
in array

Time complexity - O(n)
Space complexity - O(1)

http://www.geeksforgeeks.org/find-zeroes-to-be-flipped-so-that-number-of-consecutive-1s-is-maximized/
src/com/interview/array/Flip0sMaximum1s.java