Ezzy binary search!!!
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    vector<int> solveQueries(vector<int>& nums, vector<int>& queries) {
        int n = nums.size();
        unordered_map<int,vector<int>> mp;
        for(int i = 0;i<n;i++) {
            mp[nums[i]].push_back(i);
        }
        int q = queries.size();
        vector<int> ans(q,1e6);
        for(int i = 0;i<q;i++) {
            int a = mp[nums[queries[i]]].size();
            if(mp[nums[queries[i]]].size()<2) {
                ans[i] = -1;
                continue;
            }
            int idx1 = lower_bound(mp[nums[queries[i]]].begin(),mp[nums[queries[i]]].end(),queries[i]) - mp[nums[queries[i]]].begin();
            if(idx1==0) {
                ans[i] = min(ans[i],queries[i] + n - mp[nums[queries[i]]].back() );
                ans[i] = min(ans[i],mp[nums[queries[i]]][idx1+1]-mp[nums[queries[i]]][idx1]);
            }
            else if(idx1 == a-1) {
                ans[i] = min(ans[i],mp[nums[queries[i]]][idx1]-mp[nums[queries[i]]][idx1-1]);
                ans[i] = min(ans[i],n-queries[i]+mp[nums[queries[i]]].front());
            }
            else {
                ans[i] = min(ans[i],mp[nums[queries[i]]][idx1+1]-mp[nums[queries[i]]][idx1]);
                ans[i] = min(ans[i],mp[nums[queries[i]]][idx1]-mp[nums[queries[i]]][idx1-1]);
            }
            
        }
        return ans;
    }
};
```
['C++']