✅ HashMap || With Intuition and explanation
\n\nIntuition:\n\nFor this we need two things:\n1. map of index - value pair, so that we can know which value is at a index and update when change() function is
\n\n**Intuition**:\n\nFor this we need two things:\n1. **map of index - value pair, so that we can know which value is at a index and update when change() function is called.**\n   {why?\n    Because when we are told for replacement of a index with a new value, it means if index was present already, then we should remove the index from the list of the old value.\n    BUT HOW WE WILL GET TO KNOW VALUE AT A PARTICULAR INDEX? only if we have index-value map} \n    \n2. the question is asking for smallest index of a number:\n   **For this we need map of list of indecies assosiated to a number , but for faster we will use a set**\n   {Now question arises, why can\'t we use a priority queue, because we will have to remove an index from a list of number if we assign a new value to a index, and dedicated key removal is only possible in set data structure and not priority queue }\n        \n**Function implement explanation**        \n\n`void change function`:\n**For this function we will need two things:**\n   1.1. First we should remove the index from the list of indices of current value in map.\n   1.2. Then we will simply assign value to index and adding index to list of new number in map\n   \n`int find function`:\n1. **for this will simply check if size of index list of the given number is 0 or not, if 0 return -1**\n   {Why we are checking size?\n    Answer is that if we notice the change function, we are removing the index from list of old value,\n    so in the worst case a number that was present in many indinces earlier might get empty as it got replaced and its list of indices got \n    empty, because we remove index from list while replacement.\n    Thats why we are checking size in this case.}\n\n**C++**\n\n    class NumberContainers{\n    unordered_map<int,set<int>> KTH; //for getting kTH smallest everytime\n    unordered_map<int,int> map; //index - value pair\n    public:\n    NumberContainers() {}\n    \n    //logn \n    void change(int index, int number) {\n     \n        //remove this index from the list of indices of last mapped number if already present\n        if(map.count(index)){\n            int val= map[index];      //get its new value like i said in explanation\n            KTH[val].erase(index);\n        }\n        \n        //update key and insert inside indices list in map\n        map[index]=number;\n        KTH[number].insert(index);\n    }\n    \n    //logn\n    int find(int number) {\n        //check size\n        if(KTH[number].size()==0) return -1;\n        //return first of set whichi is minimum always\n        return *(KTH[number].begin());\n    }\n    };
['C']