[C++][Simple solution using Map (for tracking index for element) and Binary search]
Code


# Code
```cpp []
class Solution {
public:
    vector<int> solveQueries(vector<int>& nums, vector<int>& queries) {
        int sz=nums.size();
        unordered_map<int,vector<int>> dp;
        for (int i=0;i<sz;i++) dp[nums[i]].push_back(i);

        vector<int> ans(queries.size(),-1);
        int q=0,n=0, idx=-1,next,prev,s;
        for (int i=0;i<queries.size();i++){
            q=queries[i];
            n=nums[q];
            if (dp[n].size()==1) continue;
            idx = lower_bound(dp[n].begin(),dp[n].end(),q)-dp[n].begin();
            s = dp[n].size();
            next = dp[n][(idx+1)%s];
            prev = dp[n][(idx-1+s)%s];
            ans[i] = min((next+sz-q)%sz,(q-prev+sz)%sz);
        }
        return ans;
    }
};
```
['C++']