From sequential search to binary search
IntuitionApproachComplexity
Time complexity:

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)$$ -->

- Space complexity:
<!--  $$O(n)$$ -->

# Code
```python3 []
class Solution:
    def binSearch(self, nums, numIdx):
        l, r = 0 , len(nums)-1
        while(l < r):
            m = int((l+r)/2)
            if nums[m] == numIdx: return m
            if nums[m] > numIdx:
                r = m
            else:
                l = m+1
        return l
    def findMinDist(self, arrLen, nums, numIdx):
        idx = 0
        #convert this into binary search
        #while(nums[idx] != numIdx):
        #    idx +=1     
        idx = self.binSearch(nums, numIdx)
        prev = nums[idx] - nums[idx-1] if idx > 0 else  arrLen - nums[-1] + nums[0]
        next = nums[idx+1] - nums[idx] if idx < len(nums)-1 else arrLen - nums[-1] + nums[0]
        return min(prev, next)
        
    def solveQueries(self, nums: List[int], queries: List[int]) -> List[int]:
        hashmap = {}
        retval = []
        for i, v in enumerate(nums):
            if v not in hashmap:
                hashmap[v] = [i]
            else: 
                hashmap[v] += [i]
        for v in queries:
            if v > len(nums)-1 or v < 0:
                retval += [-1]
            elif len(hashmap[nums[v]]) == 1:
                retval += [-1]
            else:
                retval += [self.findMinDist(len(nums), hashmap[nums[v]], v)] 
        return retval
```
['Python3']