fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cin>>n;
  7.  
  8. vector<int> numbers(n);
  9.  
  10. for(auto& number: numbers){
  11. cin>>number;
  12. }
  13.  
  14. int distance = INT_MIN;
  15.  
  16. for(int i=0; i<n; i++){
  17. for(int j=i+1; j<n; j++){
  18. if(numbers[i] == numbers[j])distance = max(distance, j - i);
  19. }
  20. }
  21.  
  22. if(distance == INT_MIN) distance = 0;
  23.  
  24. cout<<distance;
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0s 5308KB
stdin
12
3 2 1 2 1 4 5 8 6 7 4 2
stdout
10