Simple Approach linear TC O(n) || 100%
IntuitionThe problem aims to find the minimum distance to the previous or next occurrence of the element for each query. By duplicating the array, we can handle
# Intuition
The problem aims to find the minimum distance to the previous or next occurrence of the element for each query. By duplicating the array, we can handle the circular nature of the array efficiently.

# Approach
1. **Duplicate the array** to handle circular behavior.
2. Use two **hash maps**, `prevmp` and `nextmp`, to store the previous and next occurrences of each element.
3. **Compute the previous occurrences** for each element while iterating from left to right and store the index in the `prev` array.
4. **Compute the next occurrences** for each element while iterating from right to left and store the index in the `next` array.
5. For each query, calculate the distance to the previous occurrence and the next occurrence. The answer for the query will be the minimum of these two distances.
6. If no previous or next occurrence is found, return `-1`.

# Complexity
- Time complexity:  
  $$O(n + q)$$, where `n` is the size of the array and `q` is the number of queries.
- Space complexity:  
  $$O(n)$$ - For storing the hash maps and auxiliary arrays.

# Code
```cpp []
class Solution {
public:
    vector<int> solveQueries(vector<int>& nums, vector<int>& queries) {
        int n = nums.size();

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

        vector<int> prev(nums.size());
        vector<int> next(nums.size());

        unordered_map<int, int> prevmp;
        unordered_map<int, int> nextmp;

        for (int i = 0; i < nums.size(); i++) {
            if (prevmp.find(nums[i]) == prevmp.end()) {
                prev[i] = -1;
                prevmp[nums[i]] = i;
            } else {
                prev[i] = prevmp[nums[i]];
                prevmp[nums[i]] = i;
            }
        }

        for (int i = nums.size() - 1; i >= 0; i--) {
            if (nextmp.find(nums[i]) == nextmp.end()) {
                next[i] = -1;
                nextmp[nums[i]] = i;
            } else {
                next[i] = nextmp[nums[i]];
                nextmp[nums[i]] = i;
            }
        }

        vector<int> res(queries.size());

        for (int i = 0; i < queries.size(); i++) {
            int qIndex = n + queries[i];

            int previdx = (prev[qIndex] == -1) ? n : qIndex - prev[qIndex];
            int nextidx = (next[queries[i]] == -1) ? n : next[queries[i]] - queries[i];

            if (previdx == n && nextidx == n) {
                res[i] = -1;
            } else {
                res[i] = min(previdx, nextidx);
            }
        }

        return res;
    }
};

```
['Array', 'Hash Table', 'C++']