fork download
  1. #include <iostream>
  2. #include<climits>
  3. using namespace std;
  4.  
  5. int main() {
  6. int n;
  7. cin>>n;
  8.  
  9. int a[n];
  10. for(int i=0; i<n; i++){
  11. cin>>a[i];
  12. }
  13.  
  14. int N=10000;
  15. int b[N];
  16. for(int i=0; i<N; i++){
  17. b[i]=-1;
  18. }
  19.  
  20. int mn=INT_MAX;
  21.  
  22. for(int i=0; i<n; i++){
  23. if(b[a[i]]!=-1){
  24. mn=min(mn,b[a[i]]);
  25. }
  26. else{
  27. b[a[i]]=i;
  28. }
  29. }
  30.  
  31. if(mn==INT_MAX){
  32. cout<<"-1";
  33. }
  34. else{
  35. cout<<mn+1;
  36. }
  37. return 0;
  38. }
Success #stdin #stdout 0s 5432KB
stdin
7
1 5 3 4 3 5 6
stdout
2