C# Solution for Design A Number Container System Problem
IntuitionWe need to design a system that allows:
Efficiently updating a number at a given index.
•	If an index is already occupied, we must replace the number a
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
We need to design a system that allows:
1.	Efficiently updating a number at a given index.
	•	If an index is already occupied, we must replace the number and update its mapping.
2.	Finding the smallest index for a given number.
	•	We need to store indices in a way that allows quick retrieval of the smallest one.

# Approach
<!-- Describe your approach to solving the problem. -->
We maintain two key data structures:
1.	Dictionary<int, int> indexToNumber
	•	Stores index → number mapping.
	•	Allows fast lookups and updates in O(1) time.
2.	Dictionary<int, SortedSet<int>> numberToIndices
	•	Maps number → SortedSet of indices.
	•	SortedSet<int> ensures that indices remain sorted.
	•	Min operation in SortedSet<int> allows O(1) retrieval of the smallest index.
	•	Insertion & Deletion in SortedSet is O(log N).

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
For 10⁵ operations, the worst-case runtime is O(10⁶) ≈ 1 million, which is efficient.

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
Worst-case scenario: Each index holds a unique number, leading to O(N) space usage.

# Code
```csharp []
public class NumberContainers {
    private Dictionary<int, int> indexToNumber; 
    private Dictionary<int, SortedSet<int>> numberToIndices;
    public NumberContainers() {
        indexToNumber = new Dictionary<int, int>();
        numberToIndices = new Dictionary<int, SortedSet<int>>();
    }
    
    public void Change(int index, int number) {
        if (indexToNumber.ContainsKey(index)) {
            int oldNumber = indexToNumber[index];
            if (numberToIndices.ContainsKey(oldNumber)) {
                numberToIndices[oldNumber].Remove(index);
                if (numberToIndices[oldNumber].Count == 0) {
                    numberToIndices.Remove(oldNumber);
                }
            }
        }
        indexToNumber[index] = number;
        if (!numberToIndices.ContainsKey(number)) {
            numberToIndices[number] = new SortedSet<int>();
        }
        numberToIndices[number].Add(index);
    }
    
    public int Find(int number) {
        if (numberToIndices.ContainsKey(number) && numberToIndices[number].Count > 0) {
            return numberToIndices[number].Min;
        }
        return -1;
    }
}

/**
 * Your NumberContainers object will be instantiated and called as such:
 * NumberContainers obj = new NumberContainers();
 * obj.Change(index,number);
 * int param_2 = obj.Find(number);
 */
```
['C#']