🚀🚀Simple and Efficient Approach✅
IntuitionThe problem requires efficiently storing numbers at given indices and finding the smallest index for a given number. To achieve this, we need:
A way to

## **Intuition**
The problem requires efficiently storing numbers at given indices and finding the smallest index for a given number. To achieve this, we need:
1. A way to quickly update the number at an index.
2. A method to retrieve the smallest index containing a specific number.

Using a **HashMap** to store the index-number mapping and a **TreeSet** to maintain sorted indices per number helps achieve both operations efficiently.

---

## **Approach**
1. **Data Structures Used:**
   - `store`: A `HashMap<Integer, Integer>` that maps an index to its currently assigned number.
   - `rec`: A `HashMap<Integer, TreeSet<Integer>>` where each number maps to a `TreeSet` of indices that store it.
   
2. **Operations:**
   - **`change(int index, int number)`**:
     - If the index already contains a number, remove the index from its associated `TreeSet`.
     - If the `TreeSet` becomes empty after removal, remove the entry from `rec`.
     - Update the `store` with the new number and insert the index into the corresponding `TreeSet` in `rec`.

   - **`find(int number)`**:
     - Check if the number exists in `rec` and has a non-empty `TreeSet`.
     - Return the smallest index using `first()`, or `-1` if no such index exists.

---

## **Complexity Analysis**
- **Time Complexity:**
  - `change(int index, int number)`: 
    - `store.put(index, number)`: **O(1)**
    - `rec.get(oldNumber).remove(index)`: **O(log k)** (removing from TreeSet, where *k* is the number of indices storing `oldNumber`)
    - `rec.get(number).add(index)`: **O(log k)**
    - **Overall: O(log k)**
  - `find(int number)`: 
    - `TreeSet.first()`: **O(1)**
    - **Overall: O(1)**

- **Space Complexity:**
  - `store` stores at most **O(n)** entries.
  - `rec` contains **O(n)** entries with at most **O(n)** indices in total.
  - **Overall: O(n)**


# Code
```java []
class NumberContainers {
    Map<Integer, Integer> store;
    Map<Integer, TreeSet<Integer>> rec;

    public NumberContainers() {
        store = new HashMap<>();
        rec = new HashMap<>();
    }

    public void change(int index, int number) {
        if (store.containsKey(index)) {
            int oldNumber = store.get(index);
            rec.get(oldNumber).remove(index);
            if (rec.get(oldNumber).isEmpty()) {
                rec.remove(oldNumber);
            }
        }
        store.put(index, number);
        rec.putIfAbsent(number, new TreeSet<>());
        rec.get(number).add(index);
    }

    public int find(int number) {
        return rec.containsKey(number) && !rec.get(number).isEmpty() ? rec.get(number).first() : -1;
    }
}
```
['Hash Table', 'Heap (Priority Queue)', 'Java']