<p>Given a binary array <code>nums</code> and an integer <code>k</code>, return <em>the maximum number of consecutive </em><code>1</code><em>&#39;s in the array if you can flip at most</em> <code>k</code> <code>0</code>&#39;s.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,1,1,0,0,0,1,1,1,1,0], k = 2
<strong>Output:</strong> 6
<strong>Explanation:</strong> [1,1,1,0,0,<u><strong>1</strong>,1,1,1,1,<strong>1</strong></u>]
Bolded numbers were flipped from 0 to 1. The longest subarray is underlined.</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1], k = 3
<strong>Output:</strong> 10
<strong>Explanation:</strong> [0,0,<u>1,1,<strong>1</strong>,<strong>1</strong>,1,1,1,<strong>1</strong>,1,1</u>,0,0,0,1,1,1,1]
Bolded numbers were flipped from 0 to 1. The longest subarray is underlined.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
	<li><code>nums[i]</code> is either <code>0</code> or <code>1</code>.</li>
	<li><code>0 &lt;= k &lt;= nums.length</code></li>
</ul>

class Solution {
public:
    
    struct c_queue {
        vector<int> m_queue;
        int curr = 0;
        int start = 0;
        c_queue(int i) { m_queue = vector<int>(i); }

        void push(int p) {
            m_queue[curr] = p;
            ++curr;
            return;       
        }

        int do_stuff(int p) {
            int ret = m_queue[start];
            m_queue[start] = p;
            ++start;
            start %= m_queue.size();
            return ret;
        }

    };

    int longestOnes(vector<int>& nums, int k) {
        c_queue z_s(k);

        int curr, n_z = 0;        
        int max = 0, streak = 0;

        for (int i = 0; i < nums.size(); i++) {
            curr = nums[i];
            if (curr == 1) {
                ++streak;
                continue;
            }

            if (n_z < k) {
                z_s.push(i);
                ++streak;
                ++n_z;
                continue;
            }

            max = (max >= streak) ? max : streak;
            if (k == 0) {
                streak = 0;
                continue;
            }

            streak = i - z_s.do_stuff(i);
        }

        max = (max >= streak) ? max : streak;

        return max;
    }
};
58800