C++ || JUST DOUBLE THE SIZE OF ARRAY || good for OA
IntuitionFor each index the next near by index can be the next similar item in the array or the previous similar item in the array
So we can simply iterate and
# Intuition
For each index the next near by index can be the next similar item in the array or the previous similar item in the array
So we can simply iterate and track the last index seen. And for each index now take the diff of last seen index with current one. Do this once form left to right and once from right to left.
To nullify the effect of circular array, we can consider the double size of the array to iterate it.

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
O(N)

- Space complexity:
O(N)

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

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

        vector<int> ans(m, 0);

        unordered_map<int, int> mp;
        unordered_map<int, int> mpp;

        vector<int> v1(nums.size(), 1e9), v2(nums.size(), 1e9);

        for(int i = 0; i < nums.size(); i++)
        {
            if(mp[nums[i]] == 0)
            {
                mp[nums[i]] = i + 1;
            }
            else
            {
                v1[i] = abs(mp[nums[i]] - (i + 1));
                mp[nums[i]] = i + 1;
            }
        }

        for(int i = nums.size() - 1; i >= 0; i--)
        {
            if(mpp[nums[i]] == 0)
            {
                mpp[nums[i]] = i + 1;
            }
            else
            {
                v2[i] = abs(mpp[nums[i]] - (i + 1));
                mpp[nums[i]] = i + 1;
            }
        }

        for(int i = 0; i < m; i++)
        {
            int a = queries[i];
            int b = a + n;
            int mini1 = min(v1[a], v2[a]);
            int mini2 = min(v1[b], v2[b]);

            int mini = min(mini1, mini2);

            if(mini == 1e9 || mini == n)ans[i] = -1;
            else
            {
                ans[i] = min(mini, n - mini);
            }
        }

        return ans;
    }
};
```
['Array', 'Hash Table', 'Ordered Map', 'C++']