100% beats! done using hashMap and binary search
Intuitionsince the length of nums  and queries <= 1e5 a n^2 solution will not work, so for efficient look of nearest occurence of a particular element i store t
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
since the length of nums  and queries <= 1e5 a n^2 solution will not work, so for efficient look of nearest occurence of a particular element i store them into a hashMap and get the current index using a binary search using this the time complexity boils down to O(n + mlogn)

# Approach
<!-- Describe your approach to solving the problem. -->
store all the occurence of a element in a hashMap as a list and element ist self as a key and while performing a queries extract the index from hashMap using element as key and process it's left and right occurencce and find the minimum of them and store it as result for that query.

# Complexity
- Time complexity: O(n+mlogn)
- n is length of nums
- m is length of the queries
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

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

# Code
```java []
import java.util.*;

class Solution {
    public List<Integer> solveQueries(int[] nums, int[] queries) {
        int n = nums.length, m = queries.length;
        HashMap<Integer, List<Integer>> map = new HashMap<>();
        
        
        for (int i = 0; i < n; i++) {
            map.computeIfAbsent(nums[i], k -> new ArrayList<>()).add(i);
        }
        
        List<Integer> res = new ArrayList<>();
        for (int i = 0; i < m; i++) {
            int idx = queries[i];
            int num = nums[idx];

            List<Integer> list = map.get(num);
            
            
            int pos = Collections.binarySearch(list, idx);
        

            int minDist = Integer.MAX_VALUE;
            
            
            if (pos - 1 >= 0) {
                int prevIdx = list.get(pos - 1);
                minDist = Math.min(minDist, Math.min(Math.abs(idx - prevIdx), n - Math.abs(idx - list.get(0))));
            }
            
            
            if (pos+1 < list.size()) {
                int nextIdx = list.get(pos+1);
                minDist = Math.min(minDist, Math.min(Math.abs(idx - nextIdx), n - Math.abs(idx - list.get(list.size()-1))));
            }

            
            res.add(minDist == Integer.MAX_VALUE ? -1 : minDist);
        }
        return res;
    }
}

```
if you like the solution then doupvote it andif you have any doubt or suggestion the do comment it below

['Hash Table', 'Binary Search', 'Java']