I was under the impression that unordered_map could be used as a hash map in c++. But looks like my assumption was wrong. Can someone pointed me in the right direction.
My goal here is to see in constant time if a particular value is in the hash map if not add it to hash map. I tried using unordered_map in c++ and used the find function on it, unfortunately that did not work for complicated test cases(I am running it on a coding challenge on hackerrank). Here is the code I have, I tried using operator[] also and it did not work, Any suggestions?
I think this line of code while(map.find(tmp) != map.end()) is not running in constant time. For large inputs, this is taking more time. I wanted to know if there was any better way to achieve O(1) time for map searches.