O(n) , small & easy code | Double HashMap /  Dictionary + Mod  & Backward , Forward points
Complexity
Time complexity: O(n)

Space complexity: O(2∗n)
Code


# Complexity
- Time complexity: $$O(n)$$ 
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

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

# Code
```python3 []
class Solution:
    def solveQueries(self, nums: List[int], queries: List[int]) -> List[int]:
        myDict = defaultdict(list)
        myIndexDict = defaultdict(int)
        ans = []
        size = len(nums)
        for i in range(size):
            myIndexDict[i] = len(myDict[nums[i]])
            myDict[nums[i]].append(i)
        
        for i in queries:
            tmp = myDict[nums[i]]
            if(len(tmp) == 1):
                ans.append(-1)
            else:
                val = myIndexDict[i] + 1
                val1 = myIndexDict[i] - 1
                dis = 0
                prev = 0
                if(val >= len(tmp)):
                    dis = tmp[val%len(tmp)]+(size-tmp[myIndexDict[i]])
                else:
                    dis = abs(tmp[val]-tmp[myIndexDict[i]])
                if(val1 < 0):
                    prev = (size-tmp[val1])+tmp[myIndexDict[i]]
                else:
                    prev = abs(tmp[val1]-tmp[myIndexDict[i]])
                ans.append(min(prev,dis))
        return ans
            
```
['Array', 'Hash Table', 'Ordered Map', 'Python3']