Simple Code with Explanation | Not the optimum one
ApproachCreating an index map for all the values which appears in the array. Now for processing in each query, I will look for indices with same values as given
# Approach
<!-- Describe your approach to solving the problem. -->
Creating an index map for all the values which appears in the array. Now for processing in each query, I will look for indices with same values as given in query. 

If element occurs only once, i.e., index list for that element is of size 1, then there is no other element for this, so ans[i] = -1;

Now the tricky part is, if we check for all the indices at which num[q[i]] is appeared and check for min, then it will give TLE, but for our ans, we only need to check for closest neighbours which have appeared and have same values, I am checking for 4 closest neightbour, but i think its not necessary, by checking for 2 also, it will work.  

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

- Space complexity: $$O(n)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    public List<Integer> solveQueries(int[] nums, int[] queries) {
        int n = nums.length, q = queries.length, size, min, qiInIndexMap, neighboursIndex = 0;
        List<Integer> ans = new ArrayList<>(), temp;
        Map<Integer, List<Integer>> map = new HashMap<>();

        for(int i=0; i<n; i++) {
            if(map.containsKey(nums[i])) {
                map.get(nums[i]).add(i);
            } else {
                List<Integer> al = new ArrayList<>();
                al.add(i);
                map.put(nums[i], al);
            }
        }

        for(int i=0; i<q; i++) {
            temp = map.get(nums[queries[i]]);
            size = temp.size();
            if(size == 1) {
                ans.add(-1);
                continue;
            }

            min = Integer.MAX_VALUE;
            qiInIndexMap = Collections.binarySearch(temp, queries[i]);
            for(int j=-2; j<3; j++) {
                neighboursIndex = temp.get((qiInIndexMap + j + size)%size);
                
                // System.out.println(neighboursIndex + " " + queries[i] + " " + j);
                if(neighboursIndex == queries[i]) {
                    continue;
                }

                min = Math.min(min, (neighboursIndex - queries[i] + n)%n);
                min = Math.min(min, (queries[i] - neighboursIndex + n)%n);
            }

            ans.add(min);
        }

        return ans;
    }
}
```
['Java']