LinkedHashMap || JAVA || Binary Search || Easy 
IntuitionApproachComplexity
Time complexity: O(NlogN)

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: O(NlogN)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

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

# Code
```java []
class Solution {
    public int findValue( int val,List<Integer> nums){
        int left=0,right=nums.size()-1;
        while(left<=right){
        int mid=left+(right-left)/2;

        if(nums.get(mid)==val)return mid;
        if(nums.get(mid)<val)left=mid+1;
        else right=mid-1;
        }
        return -1;
    }
    public List<Integer> solveQueries(int[] nums, int[] queries) {
        Map<Integer,List<Integer>> map=new LinkedHashMap<>();
        for(int i=0;i<nums.length;i++){
        List<Integer> list=map.getOrDefault(nums[i],new ArrayList<>());
        list.add(i);
        map.put(nums[i],list);
        }

        List<Integer> ans=new ArrayList<>();

        for(int i=0;i<queries.length;i++){
            int tar=nums[queries[i]];
            List<Integer> list=map.get(tar);
            if(list.size()==1){
                ans.add(-1);
                continue;
            }
            int pos=findValue(queries[i],list);
        
            int rightValue;
            if(pos==list.size()-1){
                 rightValue=nums.length-list.get(pos)+list.get((pos+1)%list.size());
            }else{
                 rightValue=list.get(pos+1)-list.get(pos);
            }
           
            int l;
            int leftValue;
            if(pos==0){
                l=list.size()-1;
                leftValue=list.get(pos)+(nums.length-list.get(l));
            }else{
                l=pos-1;
                leftValue=list.get(pos)-list.get(l);
            }
     
            ans.add(Math.min(leftValue,rightValue));
            
        }
        
      
       return ans;
}
}
```
['Array', 'Hash Table', 'Linked List', 'Binary Search', 'Ordered Map', 'Java']