I was trying to solve this problem but my solution keeps failing and i don't know why. I'd really appreciate if someone could help me identify what I'm getting wrong.
#include <algorithm>
#include <vector>
#include <numeric>
#include <iostream>
using namespace std;
static void paveway(){
long long n; cin >> n; vector<long long> a(n); long long ans = 1 , ant = 1;
for(long long i = 0; i < n; i++){cin >> a[i];}
for(long long i = 0; i < n - 1; i++){
if(a[i] != a[i+1]){
break;
}
ans++;
}
reverse(a.begin(),a.end());
for(long long i = 0; i < n - 1; i++){
if(a[i] != a[i+1]){
break;
}
ant++;
}
if(ans == n && ant == n) cout << -1 << endl; else cout << min(ans , ant) << endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
long long t; cin >> t;
for(;t--;)
paveway();
return 0;
}