O(n) but slow sol
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    int minFlips(string s) {
        const int N = s.size();
        return std::min(getMin(s, 0), getMin(s, 1));
    }

    // 101010_x101010_
    

    // 000x000
    // --
    // 12345|1

    // 123456|1       
    //           
    std::vector<int> getCnt(const string& s, int i) {
        const int N = s.size();
        std::vector<int>ret(2,0);
        std::string sub;
        sub.push_back(s[i%N]);
        sub.push_back(s[(i+1)%N]);
        if (sub == "10")
            ret[0]++;
        else if (sub == "01")
            ret[1]++;
        return ret;
    }

    int getMin(const string& s, int start) {
        int cnt1 = 0;// for 10
        int cnt2 = 0;// for 01
        const int W = s.size() / 2;
        int i = start;
        for (int w = 0; w < W; ++w) {
            auto cnts = getCnt(s, i);
            cnt1 += cnts[0];
            cnt2 += cnts[1];
            i += 2;
        }
        int ret = std::min(cnt1, cnt2) * 2 + W - (cnt1+cnt2);
        
        // sliding window, move by 2
        const int N = s.size();
        i = start;
        for (; i < 2 * N; i += 2) {
            auto cnts = getCnt(s, N % 2 == 1 ? i + N -1 : i + N);
            cnt1 += cnts[0];
            cnt2 += cnts[1];
            cnts = getCnt(s, i);
            cnt1 -= cnts[0];
            cnt2 -= cnts[1];
            int tmp =   std::min(cnt1, cnt2) * 2 + W - (cnt1+cnt2);
            ret = min(tmp, ret);      
        }
        return ret;
    }
};

// 110001
// if t1 --> 100011, no change.

// 110000 
// if t1 --> 100001, ans = 0

// 

// 11 --> 10  1
// 111 --> 101 1
// 1111 --> 1010 or 0101  2
// 11111 --> 10101 or 01010 2
// 111111 -->101010 or 010101 3
// it will always start by 10 or 01 
// 1011 --> 1010 is closer, swap = 1
// 0111 --> 0101 is closer, swap = 1
// 0110 --> same, swap = 2

// counting the 10 & 01 pattern, if we can only use t2
// solution will be min(cnt(10), cnt(01))*2 + N/2 - (cnt(01)+cnt(10))
// for example
// 101111, cnt(10) = 1, cnt(01) = 0, cnt(10) = 1 cnt(11or00) = 2. 2*1+0*2 = 2
// 101101, cnt(10) =1 , cnt(01) = 1, cnt(11) = 6/2 - cnt(01) -cnt(10) = 1
//  final = min(cnt(01),cnt(10))*2 + cnt(11) = 2+1 = 3

// what if we can use type1 ?
// try to reduce min(cnt(10), cnt(01))*2 + N/2 - (cnt(01)+cnt(10))
// 1101010x1101010

// brute force --> N^2, can we be faster ?
// shift(0) = shift(2) = shift(4)...
// shift(1) = shigt(3) = shift(5)...
// we only need to consider shift(0) and shift(1).

// 01 00 10 01 10 1  cnt(01) = 2, cnt(10) = 2, len = 5. 1 + 2*2 = 4  
// 10 01 00 11 01 0
// 01001001101x01001001101

// 10 01 00 11 01x0

// 01 00 11 01x010
// 3op1 01001101010 

//  01001001101x01001001101
// s1 10 01 00 11 01x0  cnt(10) = 1, cnt(01) = 2  
// s3 01 00 11 01x01 0  cnt(10) = 0 cnt(01) = 3

// if odd --> head-cnt -= 1 += new?
// 
```
['C++']