C++ Solution || 2 Hashmap Solution 
IntuitionThe goal is to efficiently store and retrieve indices of numbers while supporting updates. Using hash maps allows quick lookups and insertions, and a s
# Intuition
The goal is to efficiently store and retrieve indices of numbers while supporting updates. Using hash maps allows quick lookups and insertions, and a set ensures sorted access to indices.

# Approach
1. **Data Structures:**
   - `unordered_map<int, int> indmp`: Maps indices to their assigned numbers.
   - `unordered_map<int, set<int>> nummp`: Maps each number to a sorted set of indices.
2. **Operations:**
   - `change(index, number)`: Updates the index with the given number, ensuring old mappings are removed.
   - `find(number)`: Returns the smallest index for the given number.

# Complexity
- **Time Complexity:**
  - `change(index, number)`: $$O(log n)$$ due to insertion/deletion in `set`.
  - `find(number)`: $$O(1)$$ as it retrieves the smallest element in `set`.
- **Space Complexity:** $$O(n)$$ for storing mappings.

# Code
```cpp
class NumberContainers {
private:
    unordered_map<int, int> indmp;
    unordered_map<int, set<int>> nummp;

public:
    NumberContainers() {}

    void change(int index, int number) {
        if (indmp.find(index) != indmp.end()) {
            int prevnum = indmp[index];
            if (prevnum == number)
                return;
            nummp[prevnum].erase(index);
            if (nummp[prevnum].empty()) {
                nummp.erase(prevnum);
            }
        }
        indmp[index] = number;
        nummp[number].insert(index);
    }

    int find(int number) {
        if (nummp.find(number) != nummp.end()) {
            return *nummp[number].begin();
        }
        return -1;
    }
};
```
![d3550b79-52c8-4704-846f-c00daecb5632_1737784461.667478.png](https://assets.leetcode.com/users/images/1d0e83ed-0b31-4c71-a82f-83ce04f2752e_1738998277.5578916.png)



['Hash Table', 'Design', 'Ordered Set', 'C++']