Minimum Number of swaps required to group all ones together in array of 0s and 1s
The algorithm is sound, and it's O(N). There are only two things I see you can improve.

Make use of the standard library

The C++ library comes with a lot of functions, including ones that can take care of summing elements of a vector for you. So to find the number of ones in the input vector, you can just write:

#include &lt;algorithm&gt;
...
int window = std::accumulate(std::begin(data), std::end(data), 0);


You don't need onesTillNow

When moving your window over the input array, you don't need to store all the number of ones for every window position. You just want to know the maximum number of ones in a window. If you just have a single variable int onesInWindow, and initialize it with the sum of ones in the first window:

int onesInWindow = std::accumulate(std::begin(data), std::begin(data) + window, 0);
int maxOnes = onesInWindow;


Then you can iterate over all the other window positions like this:

for(int i = window; i &lt; size; i++) {
    onesInWindow -= data[i - window];
    onesInWindow += data[i];
    maxOnes = std::max(maxOnes, onesInWindow);  
}