Optimal Solution | Two Map Solution | TC::O(n) | C++ 
Code[1/2] [ TLE ]Code[2/2] [Optimal]
# Code[1/2] [ TLE ] 
```cpp []
/*
By    :: savetrees
Used  :: Single Map
*/
class NumberContainers {
public:
    unordered_map<long int,long int>index_num; 
    NumberContainers(){}
    void change(int index,int number) {
        index_num[index]=number;}
    int find(int number){
        long mini=INT_MAX; 
        for (const auto &entry:index_num) {
            if (entry.second==number) {
                mini=min(mini,entry.first);}}
        return(mini==INT_MAX)?-1:mini;
    }};
    }
};

```
# Code[2/2] [Optimal]
```cpp []
/*
By    :: savetrees
Used  :: Two Unordered Map (Optimal)
*/
class NumberContainers {
public:
    unordered_map<int,int>index_value;
    unordered_map<int,set<int>>value_index;
    NumberContainers(){}
    void change(int index,int number) {
    if(index_value.find(index)!=index_value.end())
    {
        int old=index_value[index];
        value_index[old].erase(index);
        if(value_index[old].empty())value_index.erase(old);  
    }
    index_value[index]=number;
    value_index[number].insert(index); 
    }
    int find(int number) {
        if(value_index.find(number)==value_index.end())return -1;
        return *value_index[number].begin();
    }
};

```
['C++']