Binary Search + Hash Table C++ [Easy to understand]
Intuition & ApproachFirst I needed a mapping from each unique number to all of its indices. By definition, the indices vector is sorted, so I can know take adva
# Intuition & Approach
<!-- Describe your first thoughts on how to solve this problem. -->
First I needed a mapping from each unique number to all of its indices. By definition, the indices vector is sorted, so I can know take advantage of this fact and do binary search to find positioning of the index and then find neighboring indices. 

The only thing left was to break down the algorithm into 4 distinct cases to account for the circular nature of the nums vector.

# Complexity
Assume $$N$$ is the number of elements in `nums`
Assume $$Q$$ is the number of queries
Assume $$K$$ is the number of distinct elements in `nums`
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

$$O(N + Qlog(N))$$ in the worst case assuming that your entire nums vector is comprised of the same element

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
$$O(N + Q)$$ in the worst case, average case is $$O(K + Q)$$

# Code
```cpp []
class Solution {
public:
    vector<int> solveQueries(vector<int>& nums, vector<int>& queries) {
        // {num -> [idx]}
        unordered_map<int, vector<int>> mapping;
        for (int i = 0; i < nums.size(); i++) {
            mapping[nums[i]].push_back(i);
        }

        vector<int> results;

        for (int num_idx: queries) {
            int num = nums[num_idx];
            const vector<int>& idxs = mapping[num];
            if (idxs.size() == 1) {
                results.push_back(-1);
                continue;
            }
            auto it = std::lower_bound(idxs.begin(), idxs.end(), num_idx);
            int index_in_idxs = std::distance(idxs.begin(), it);
            int min_dist = 10000000;
            int num_size = nums.size();
            if (idxs.size() >= 1) {
                // CASE 1: Keep going left and hit the first element on the right edge of the array
                min_dist = std::min(idxs[index_in_idxs] + num_size - idxs[idxs.size() - 1], min_dist);
            }
            if (index_in_idxs >= 1) {
                // CASE 2: Keep going right and hit the first element on the left edge of the array
                min_dist = std::min(num_size - idxs[index_in_idxs] + idxs[0], min_dist);
                // CASE 3: Go the nearest element to your immediate left.
                min_dist = std::min(idxs[index_in_idxs] - idxs[index_in_idxs - 1], min_dist);
            }
            if (index_in_idxs + 1 < idxs.size()) {
                // CASE 4: Go the nearest element to your immediate right.
                min_dist = std::min(idxs[index_in_idxs + 1] - idxs[index_in_idxs], min_dist);
            }

            results.push_back(min_dist);
        }

        return results;
    }
};
```
['Hash Table', 'Binary Search', 'C++']