Source Code
#include <iostream>

using namespace std;

int t,n,a[200000],ans[10000];

int main()
{
    cin >> t;
    int max = a[0];
    for (int i = 0; i < t; i++){
        cin >> n;
        int temp = 0;
        for (int j = 0; j < n; j++){
            cin >> a[j];
            if (max == a[j]){
                temp++;
            }
            if (max < a[j]){
                max = a[j];
                temp = 0;
            }
        }
        if (temp > 1){
            ans[i] = -1;
        }
        else{
            ans[i] = n - temp;
        }
        
    }
    
    for(int i = 0; i < t; i++){
        cout << ans[i] << "\n";
    }
    return 0;
}
Copy
Proud Competitors laith.tak01
GNU G++17
11 ms
312 KB
Wrong Answer