easy to understand, c++
Code
# Code
```cpp []
class Solution {
public:
    int helper(vector<int>& nums, int idx, int m)
    {
        int n = nums.size();
        if(n == 1) return -1;
        int current = lower_bound(nums.begin(), nums.end(), idx) - nums.begin();
        int dis = INT_MAX;
        int next = (current + 1) % n;
        int prev = (current + n - 1) % n;
        dis = min(dis, abs(nums[next] - idx));
        dis = min(dis, abs(nums[prev] - idx));
        dis = min(dis, m - abs(nums[next] - idx));
        dis = min(dis, m - abs(nums[prev] - idx));
        return dis;
    }
    vector<int> solveQueries(vector<int>& nums, vector<int>& queries) {
        int n = nums.size();

        unordered_map<int, vector<int>> map;

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

        vector<int> result;

        for(int i = 0; i < queries.size(); ++i)
        {
            result.push_back(helper(map[nums[queries[i]]], queries[i], n));
        }

        return result;
    }
};
```
['C++']