MOST EASIEST APPORACH AND UNDARSTANING SOLUTION :->>>>>
Approachby using nums(vector) three timesComplexityTime Complexity: O((n + m) log n)
Space Complexity: O(n + m)Code

# Approach
by using nums(vector) three times

# Complexity
Time Complexity: O((n + m) log n)
Space Complexity: O(n + m)

# 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>> s;

     for ( int i=0;i<3*n;i++){

         s.insert({nums[i],i});   
     }
     vector<int> ans;

     for ( auto q: queries){
         q = q +n;

         auto it = s.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++']