Source Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int arr[n];
    for(int i = 0; i < n; i++){
        cin >> arr[i];
    }
    int zero = 0, one = 0, ans = 0;
    for(int i = 0; i < n; i++){
        if(arr[i] == 1)
          one++;
          else
           zero++;
        if(zero && one){
            ans++;
            zero = 0;
            one = 0;
        }
    }
    cout << ans << '\n';
}
Copy
Tha Bits monther abu zaina1
GNU G++17
6 ms
1.1 MB
Accepted