100% BEAT C++ EASY SOLN || SET ||
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();
        for(int i=0;i<n;i++) nums.push_back(nums[i]);
        for(int i=0;i<n;i++) nums.push_back(nums[i]);
        set<pair<int,int>>st;
        for(int i=0;i<3*n;i++) st.insert({nums[i],i});
        vector<int>ans;
        for(int q:queries){
            q+=n;
            auto it=st.lower_bound({nums[q],q});
            ans.push_back(min({n,q-prev(it)->second,next(it)->second-q}));
            if(ans.back()==n) ans.back()=-1;        }
            return ans;
    }

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