Source Code
/*
     Author: Asmaa Raafat
*/
/////////////////////////////"THINK TWICE... CODE ONCE"/////////////////////////////////.
#include <bits/stdc++.h>
#define ll long long
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
/*ll freqfac[22] ={1};
void getfac(int n)
{
    for(int i=1; i<=20; i++)
    {
        freqfac[i] = freqfac[i-1] * i;
    }
}*/
int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("primes.in", "r", stdin);
    #endif
    fast;
    int t;
    cin>>t;
    while(t--)
    {
        int n, c=0;
        cin>>n;
        int arr[n];
        vector<int>b;
        ll cnt =0;
        for(int i=0; i<n; i++)
        {
            cin>>arr[i];
        }
        for(int i=0; i<n; i++)
        {
            if(arr[i] != arr[i+1])
            {
                b.push_back(arr[i]);
            }
            else
            {
                cnt ++;
            }
        }
        int sz =b.size();
        if( sz>0 && cnt>0)
        {
            cout<<2<<endl;
        }
        else
        {
            cout<<sz<<endl;
        }

    }
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/
Copy
Proud Competitors asmaa_raafat
GNU G++17
33 ms
312 KB
Wrong Answer