HashMap + Binary Search Approach
Approach
Build a Map: Store the indices of each element in nums using a map.
Process Queries: For each query:

If the element appears multiple times, use binary
<!-- # Intuition -->
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->
* Build a Map: Store the indices of each element in nums using a map.
* Process Queries: For each query:
  * If the element appears multiple times, use binary search to locate the closest index in the sorted indices list.
* Calculate Minimum Distance: Compute the minimum circular distance using:
  *                           min(∣i−j∣,n−∣i−j∣)

# Complexity
- Time complexity: O((N + M) * log(K))
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

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

# Code
```cpp []
class Solution {
private:
    int find(const vector<int> &idx, int i, int n){
        int m = idx.size();
        int s = 0, e = m - 1, j = -1;
        while(s <= e){
            int mid = s + (e - s) / 2;
            if(idx[mid] == i){
                j = mid;
                break;
            }
            else if(idx[mid] > i) e = mid - 1;
            else s = mid + 1;
        }

        int ans = INT_MAX;
        if(j + 1 < m) ans = min({ans, cal(idx, idx[j], idx[j + 1], n)});
        if(j - 1 >= 0) ans = min({ans, cal(idx, idx[j], idx[j - 1], n)});
        if(j != 0) ans = min({ans, cal(idx, idx[j], idx[0], n)});
        if(j != m - 1) ans = min({ans, cal(idx, idx[j], idx[m - 1], n)});
        return ans;
    }

int cal(const vector<int> &idx, int i, int j, int n){
    return min({abs(i - j), abs(n - abs(i - j))});
}
public:
    vector<int> solveQueries(vector<int>& nums, vector<int>& queries) {
        int n = nums.size(), m = queries.size();
        map<int, vector<int>> mp;
        for(int i = 0; i < n; i++){
            mp[nums[i]].push_back(i);
        }

        vector<int> ans(m, -1);
        for(int i = 0; i < m; i++){
            const vector<int> &idx = mp[nums[queries[i]]];
            if(idx.size() > 1){
                ans[i] = find(idx, queries[i], n);
            }
        }
        return ans;
    }
};
```
['Array', 'Hash Table', 'Binary Search', 'C++']