VERY EASY || BEGINNERS FRIENDLY
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

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

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$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;
    }
};
```
['C++']