Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- #define pb push_back
- int main()
- {
- _test
- {
- int n;
- cin>>n;
- vector<int> a(n);
- for(auto &e: a)
- cin>>e;
- if(*max_element(a.begin(), a.end()) ==
- *min_element(a.begin(), a.end()))
- {
- cout<<"-1\n";
- continue;
- }
- int ans=n, cnt=0;
- for(int i=0; i<n; i++)
- {
- if(a[0] == a[i]) cnt++;
- else
- {
- ans = min(ans, cnt);
- cnt = 0;
- }
- }
- ans = min(ans, cnt);
- cout<<ans<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement