crowulll

Untitled

Aug 13th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. using namespace std;
  4. int t;
  5. int main(){
  6.     cin >> t;
  7.     while (t--){
  8.         int n; cin >> n; int m = 1e9;
  9.         vector <int> pos(n + 1, 0);
  10.         vector <int> num(n + 1, 0);
  11.         for (int i = 1; i < n + 1; ++i){
  12.             int x; cin >> x;
  13.             num[x]++;
  14.             if (num[x] > 1){
  15.                 m = min(m, i - pos[x] + 1);
  16.             }
  17.             pos[x] = i;
  18.         }
  19.         if (n!= 1 && m != 1e9) cout << m << endl;
  20.         else cout << -1 << endl;
  21.  
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment