Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- int t;
- cin >> t;
- while(t--)
- {
- int n;
- cin >> n;
- map<int, vector<int>> mp;
- for(int i = 0; i < n; i++)
- {
- int a;
- cin >> a;
- mp[a].push_back(i);
- }
- int ans = n;
- bool f = 1;
- for(auto i : mp)
- {
- auto v = i.second;
- for(int j = 0; j < v.size() - 1; j++)
- {
- f = 0;
- ans = min(ans, v[j + 1] - v[j] + 1);
- }
- }
- if(f)
- cout << -1;
- else
- cout << ans;
- cout << "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement