0% found this document useful (0 votes)
2 views

cf b (1)

The document contains a C++ program that processes multiple test cases to find the minimum number of consecutive occurrences of the first element in a list of integers. If all elements in the list are the same, it outputs -1. The program uses standard input/output operations and employs data structures like vectors and maps for efficient processing.

Uploaded by

yug maheshwari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

cf b (1)

The document contains a C++ program that processes multiple test cases to find the minimum number of consecutive occurrences of the first element in a list of integers. If all elements in the list are the same, it outputs -1. The program uses standard input/output operations and employs data structures like vectors and maps for efficient processing.

Uploaded by

yug maheshwari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <bits/stdc++.

h>
#define int long long
#define vi vector<int>
#define vb vector<bool>
#define get(a) \
for (auto &i : a) \
cin >> i
#define put(a) \
for (auto &i : a) \
cout << i << " "
#define endl "\n"
#define sp << " " <<
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
const int N = 1e6 + 2;
const int mod = 1e9 + 7;
const int INF = LLONG_MAX;
using namespace std;

signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;cin>>t;
while(t--){
int n;cin>>n;
vector<int> v;
map<int,int> ma;
for(int i=0;i<n;i++){
int x;cin>>x;
v.push_back(x);
ma[x]++;
}
if(ma.size()==1){
cout<<-1<<endl;
continue;
}
int x=v[0];
int ix=0;
int ans=n;

for(int i=0;i<n;i++){
if(v[i]==v[0]){
ix++;
}
else{

ans=min(ans,ix);
ix=0;
}

}
ans=min(ans,ix);

cout<<ans<<endl;
}

You might also like