C++ | Binary Search | Hash Table | Easy and Clean code
Code
# Code
```cpp []
class Solution {
    int n;
    int harsh(int k, vector<int> &a){
        int m=a.size();
        int lo=0, hi=m-1, mid;
        int d;

        while(hi-lo>1){
            mid=(hi+lo)/2;

            if(a[mid]<=k) lo=mid;
            else hi=mid-1;
        }

        if(k==a[hi]) d=hi;
        else d=lo;

        if(d==m-1) return min(n-k+a[0], k-a[d-1]);
        else if(d==0) return min(a[d+1]-k, n-a[m-1]+k);
        return min(a[d+1]-k, k-a[d-1]);
    }
public:
    vector<int> solveQueries(vector<int>& nums, vector<int>& queries) {
        n=nums.size();
        unordered_map<int, vector<int>> mp;

        for(int i=0; i<n; i++){
            mp[nums[i]].push_back(i);
        }

        vector<int> ans;

        for(auto &i: queries){
            if(mp[nums[i]].size()==1){
                ans.push_back(-1);
            }
            else{
                ans.push_back(harsh(i,mp[nums[i]]));
            }
        }

        return ans;
    }
};
```
['Hash Table', 'Binary Search', 'C++']