O(N) time complexity , with out binary search 
Intuitioneverytime we encounter any number we will see its closest distance with previous occurence and first occurence of that number(becuase array is circular
# Intuition

everytime we encounter any number we will see its closest distance with previous occurence and first occurence of that number(becuase array is circular) 

but when we will update its distance , we will also update distance of previous occurence and the first occurence

# 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
```java []
class Solution {
    public List<Integer> solveQueries(int[] nums, int[] queries) {
        
        HashMap<Integer,int[]> index = new HashMap<>() ; 
        
        HashMap<Integer,Integer> distance = new HashMap<>() ; 
        
        
        for( int i = 0 ; i < nums.length ; i++)
        {
            if( index.containsKey(nums[i]))
            { 
                int temp[] = index.get(nums[i]) ; 
                
                
                int min1 = i - temp[1] ; 
                
                
                int min2 = nums.length-i + temp[0] ; 
                
                
                System.out.println("number hai = " + nums[i] + "" + min1 + " " + min2) ; 
                
                int min = Math.min(min1, min2) ; 
                
                distance.put(i, min ) ; 
                
                
                if( distance.containsKey(temp[1]))
                {
                    distance.put(temp[1], Math.min(distance.get(temp[1]), min1)) ; 
                }
                else
                distance.put(temp[1] , min1) ; 

                      
                if( distance.containsKey(temp[0]))
                {
                    distance.put(temp[0], Math.min(distance.get(temp[0]), min2)) ; 
                }
                else
                distance.put(temp[0] , min2) ; 



                    
                
                temp[1] = i ; 
            }
            else
            {
                int temp[] = {i , i } ; 
                
                index.put(nums[i] , temp) ; 
                
                
            }
        }
        
        
        
        List<Integer> list = new ArrayList<>() ; 
        
        
        for( int i = 0 ; i < queries.length ; i++)
        {
            if( distance.containsKey(queries[i]))
            {
                list.add(distance.get(queries[i])) ; 
            }
            else
                list.add(-1) ; 
        }
        
        return list ; 
    }
    
}
```
['Java']