Simple beginner friendly C++ Solution - Beats 100%
IntuitionFor each number n in nums, keeping a vector of indices whose value is n. Now we just need to find the minimum distance between the neighbouring indices
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
For each number `n` in `nums`, keeping a vector of indices whose value is `n`. Now we just need to find the minimum distance between the neighbouring indices. 
# Approach
<!-- Describe your approach to solving the problem. -->
1. Use a map to keep track of indices.
2. Check if the number is present in 2 or more indices.
3. If yes then find the index we are talking about.
4. Compare and find the minimum distance for the neighbouring indices since they are the closest.
# Complexity
- Time complexity: $$O(n log n)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: $$O(n)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
plzz upvote if you like the approach
# Code
```cpp []
class Solution {
public: 
    vector<int> solveQueries(vector<int>& nums, vector<int>& queries) {
        vector<int> ans(queries.size(),-1);
        unordered_map<int,vector<int>> mp;
        for(int i=0;i<nums.size();i++){
            mp[nums[i]].push_back(i);
        }
        int sz=nums.size();
        for(int i=0;i<queries.size();i++){
            int n=nums[queries[i]];
            if(mp[n].size()<2)continue;
            auto it = lower_bound(mp[n].begin(), mp[n].end(), queries[i]);
            int t=mp[n].size();
            int cur=it-mp[n].begin();
            int x=mp[n][(cur-1+t)%t];
            int y=mp[n][(cur+1)%t];
            int z=mp[n][cur];
            int dist1=min((z-x+sz)%sz,(x-z+sz)%sz), dist2=min((z-y+sz)%sz,(y-z+sz)%sz);
            ans[i]=min(dist1,dist2);
        }
        return ans;
    }
};
```
['Array', 'Binary Search', 'Ordered Map', 'C++']