Efficient Index Management Using Sorted Sets for Fast Retrieval in Python
ApproachWe maintain two dictionaries:
idx: Maps an index to its assigned number.
numbers: Maps each number to a SortedSet of indices (to efficiently retrieve th
#  Approach
We maintain two dictionaries:

- idx: Maps an index to its assigned number.
- numbers: Maps each number to a SortedSet of indices (to efficiently retrieve the smallest index).

## Operations:

change(index, number): 
- If the index is already present, remove it from the set of its previous number.
- Update idx[index] to the new number.
- Insert index into the corresponding SortedSet for number.

find(number):
- If number exists in numbers, return the smallest index using SortedSet.
Otherwise, return -1.

# Complexity
- Time Complexity:
change(): O(logn) (due to SortedSet operations)
find(): O(1) (fetching first element)

- Space Complexity: O(n) (storing indices in SortedSet)

# Code
```python3 []
from sortedcontainers import SortedSet

class NumberContainers:

    def __init__(self):
        self.numbers = {}  # Maps numbers to SortedSet of indices
        self.idx = {}  # Maps indices to numbers

    def change(self, index: int, number: int) -> None:
        if index in self.idx:  # If index already exists
            prev = self.idx[index]
            if prev in self.numbers:  # Remove index from previous number's set
                self.numbers[prev].discard(index)
                if not self.numbers[prev]:  # Remove entry if set is empty
                    del self.numbers[prev]
        
        # Update index mapping
        self.idx[index] = number
        # Add index to the new number's set
        if number not in self.numbers:
            self.numbers[number] = SortedSet()
        self.numbers[number].add(index)

    def find(self, number: int) -> int:
        if number in self.numbers and self.numbers[number]:
            return next(iter(self.numbers[number]))  # Return smallest index
        return -1

```
['Python3']