O(n + q log k) Binary Search 
IntuitionTo efficiently find the closest index with the same value in a circular array, we should preprocess the indices of each unique number in nums. A dictio
# Intuition
To efficiently find the closest index with the same value in a circular array, we should preprocess the indices of each unique number in `nums`. A dictionary mapping each value to its sorted list of occurrences allows us to efficiently locate the nearest index using binary search.

# Approach
1. **Preprocessing**:  
   - Use a dictionary (`index_map`) to store all occurrences of each unique value in `nums` as a sorted list.
   
2. **Processing Queries**:  
   - For each query, retrieve the sorted list of indices where the queried value appears.
   - Use **binary search** to efficiently locate the closest index.
   - The circular nature of the array means we should consider distances in both forward and backward directions.

3. **Binary Search for Nearest Index**:  
   - Use `bisect_left` to find the closest occurrence in sorted order.
   - Compare with neighboring indices to determine the minimum circular distance.

# Complexity
- **Preprocessing:**  
  - Constructing `index_map`: O(n), where n is the size of `nums`.
- **Query Processing:**  
  - Each query requires a **binary search**: O(log k) where k is the number of occurrences of the value in `nums`.
  - **Final complexity:** O(n + q log k), where q is the number of queries.

# Code
```python
from bisect import bisect_left
from collections import defaultdict

class Solution:
    def closestEqualIndices(self, nums: List[int], queries: List[int]) -> List[int]:
        # Step 1: Preprocess indices of each number
        index_map = defaultdict(list)
        n = len(nums)
        
        for i, num in enumerate(nums):
            index_map[num].append(i)
        
        result = []
        
        # Step 2: Process each query
        for q in queries:
            num = nums[q]
            indices = index_map[num]
            
            # If only one occurrence exists, answer is -1
            if len(indices) == 1:
                result.append(-1)
                continue
            
            # Step 3: Find closest index using binary search
            pos = bisect_left(indices, q)
            min_dist = float('inf')
            
            # Check closest element before or after `q`
            if pos < len(indices):  # Right-side candidate
                min_dist = min(min_dist, (indices[pos] - q) % n)
            if pos > 0:  # Left-side candidate
                min_dist = min(min_dist, (q - indices[pos - 1]) % n)
            
            result.append(min_dist)
        
        return result

['Hash Table', 'Binary Search', 'Python3']