Python approach using two hashmaps.
IntuitionApproachComplexity

Time complexity:
O(n)


Space complexity:
O(n)

Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
O(n)

- Space complexity:
O(n)

# Code
```python3 []
class Solution:
    def solveQueries(self, nums: List[int], queries: List[int]) -> List[int]:
        h_map_1 = {}
        h_map_2 = {}
        o_l = len(nums)
        nums = nums + nums[: len(nums) - 1]
        for i in range(len(nums)):
            h_map_2[i] = math.inf
        for i in range(len(nums)):
            if nums[i] in h_map_1.keys():
                h_map_2[h_map_1[nums[i]]] = min(
                    h_map_2[h_map_1[nums[i]]], abs(h_map_1[nums[i]] - i)
                )
                h_map_2[i % o_l] = min(h_map_2[i % o_l], abs(h_map_1[nums[i]] - i))
                h_map_1[nums[i]] = i
            else:
                h_map_1[nums[i]] = i
        res = []
        for i in queries:
            res.append(
                -1 if (h_map_2[i] == math.inf or h_map_2[i] >= o_l) else h_map_2[i]
            )
        return res

```
['Python3']