Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- using namespace std;
- int t;
- int main(){
- cin >> t;
- while (t--){
- int n; cin >> n; int m = 1e9;
- vector <int> pos(n + 1, 0);
- vector <int> num(n + 1, 0);
- for (int i = 1; i < n + 1; ++i){
- int x; cin >> x;
- num[x]++;
- if (num[x] > 1){
- m = min(m, i - pos[x] + 1);
- }
- pos[x] = i;
- }
- if (n!= 1 && m != 1e9) cout << m << endl;
- else cout << -1 << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment