fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using std::cin;
  5. using std::cout;
  6. using std::endl;
  7. using std::vector;
  8.  
  9. int checkFreq(const vector<int>& a) {
  10. vector<int> freq(10001, 0);
  11. for (int num : a) {
  12. freq[num]++;
  13. if (freq[num] >= 3) {
  14. return num;
  15. }
  16. }
  17. return -1;
  18. }
  19.  
  20. int main() {
  21. int t;
  22. cin >> t;
  23.  
  24. for (int i = 0; i < t; i++) {
  25. int n;
  26. cin >> n;
  27. vector<int> a(n);
  28. for (int j = 0; j < n; j++) {
  29. cin >> a[j];
  30. }
  31. cout << checkFreq(a) << endl;
  32. }
  33.  
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0.01s 5280KB
stdin
7
1
1
3
2 2 2
7
2 2 3 3 4 2 2
8
1 4 3 4 3 2 4 1
9
1 1 1 2 2 2 3 3 3
5
1 5 2 4 3
4
4 4 4 4
stdout
-1
2
2
4
1
-1
4