#include <bits/stdc++.h>
using namespace std;
int main() {
int i,j,n,k=0,l,b1,d1=0;
cin >> n ;
int a[n],b[n];
for(i=0;i<n;i++) cin >> a[i];
k = 0;
l = a[0] ;
for(i=0;i<n;i++){
for(j=i+1;j<n;j++){
if(a[i] == a[j]){
b1 = j-i;
d1 = 1;
}
}
if(l>b1) l = b1 ;
}
if(d1!=0)
cout << l <<endl;
else
cout << "-1" <<endl;
return 0;
}
using namespace std;
int main() {
int i,j,n,k=0,l,b1,d1=0;
cin >> n ;
int a[n],b[n];
for(i=0;i<n;i++) cin >> a[i];
k = 0;
l = a[0] ;
for(i=0;i<n;i++){
for(j=i+1;j<n;j++){
if(a[i] == a[j]){
b1 = j-i;
d1 = 1;
}
}
if(l>b1) l = b1 ;
}
if(d1!=0)
cout << l <<endl;
else
cout << "-1" <<endl;
return 0;
}
No comments:
Post a Comment