Readable | Intuitive | Simple and Concise code
Intuition
As we need to calculate the distance of elements at 2 different indices => map or dict
For every query we need a result, based on the constraints we n
# Intuition
1. As we need to calculate the distance of elements at 2 different indices => **map or dict**
2. For every query we need a result, based on the constraints we need to perform an operation having atmots O(logn) complexity => **binary search**
3. The word **circular** is important => **Math & modulus**

# Approach
1. Store the indices for occurences of each element in a map like
    `Map(value->[indices])`
2. For each query handle edge cases first
    - query index out of range
    - single occurence of element
3. Perform binary search to get the position of query index in the `map[element]` where element is `nums[query index]]`, say `ind`
4. Calculate left and right distance using the immediate neighbours of `ind` in a circular fashion from the indices array by handling edge cases(as it is circular)
    - if the `ind` is at start, then its **previous index** will be greater than `ind` so we need to perform `prev-n`
    - if the `ind` is at end, then its **next index** will be smaller than `ind` so we need to perform `next+n`

# Complexity
- Time complexity: $$O(k * logn)$$, k is no. of queries

- Space complexity: $$O(n)$$

# Raw Code (contest)
```python3 []
class Solution:
    def solveQueries(self, nums: List[int], qs: List[int]) -> List[int]:
        n=len(nums)
        
        f=defaultdict(list)
        for i,num in enumerate(nums):
            f[num].append(i)

        def helper(q):
            if q>=n:return -1
            num=nums[q]
            arr=f[num]
            nn=len(arr)
            if nn==1:return -1
            ind=bisect_left(arr,q)
            prev=arr[(ind-1+nn)%nn]
            next=arr[(ind+1)%nn]
            if prev>q:prev-=n
            if next<q:next+=n
            left=q-prev
            right=next-q
            # print(q,num,arr,prev,q,next,left,right)
            return min(left,right)
        
        res=[helper(q) for q in qs]

        return res
```

# Readable Code
```python3 []
class Solution:
    def solveQueries(self, nums: List[int], queries: List[int]) -> List[int]:
        nums_length = len(nums)

        indMap = defaultdict(list)
        for index, element in enumerate(nums):
            indMap[element].append(index)

        def getMinDistance(query_index):
            # query_index index out of range
            if query_index >= nums_length: 
                return -1

            element = nums[query_index]
            indices = indMap[element]
            indices_length = len(indices)

            # single occurence of element
            if indices_length == 1:
                return -1

            # calculate position of query_index in indices
            query_index_position = bisect_left(indices, query_index) # O(logn)

            previous_position = indices[(query_index_position - 1 + indices_length) % indices_length]
            if previous_position > query_index:
                previous_position -= nums_length

            next_position = indices[(query_index_position + 1) % indices_length]
            if next_position < query_index:
                next_position += nums_length

            left_distance = query_index - previous_position
            right_distance = next_position - query_index
            
            return min(left_distance, right_distance)

        result = [getMinDistance(query_index) for query_index in queries] # O(k)

        return result

```
['Math', 'Binary Search', 'Ordered Map', 'Python3']