Binary Search + hashmap
IntuitionStore all the indices in a hashmap of lists, then use binary search to find that elements index. Return the minimum circular distance.Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Store all the indices in a hashmap of lists, then use binary search to find that elements index. Return the minimum circular distance.

# Code
```python3 []
class Solution:
    def search(self, q, arr):
        i, j = 0, len(arr)-1
        while i <= j:
            mid = (i+j)>>1
            if arr[mid] < q:
                i = mid+1
            elif arr[mid] == q:
                return mid
            else:
                j = mid-1
        
    def solveQueries(self, nums: List[int], queries: List[int]) -> List[int]:
        n = len(nums)
        d = defaultdict(list)
        ans = [0]*len(queries)
        for i, num in enumerate(nums):
            d[num].append(i)
        for i, q in enumerate(queries):
            arr = d[nums[q]]
            if len(arr) == 1:
                ans[i] = -1
                continue
            index = self.search(q, arr)
            if index == len(arr)-1:
                ans[i] = min(arr[index]-arr[index-1], 
                            n-arr[index]+arr[0])
            elif index == 0:
                ans[i] = min(arr[index+1]-arr[index],
                            n-arr[-1]+arr[index])
            else:
                ans[i] = min(arr[index]-arr[index-1],
                            arr[index+1]-arr[index])
        return ans
```
['Hash Table', 'Binary Search', 'Python3']