![]() |
VOOZH | about |
In C++, multimaps are associative containers similar to maps, but unlike maps, they can store multiple values mapped to the same key. In this article, we will learn how to find all the occurrences of a specific key in a multimap in C++.
Example:
Input:
myMutimap = {{ "id", "111" }, { "id", "112" }, { "student", "John" },
{ "student", "Bob" }, { "student", "Mike" } };
Output:
Occurrences of the key student are:
John Bob Mike
To find all occurrences of a specific key in a multimap in C++ STL, we can use the std::multimap::equal_range() function, which returns a std::pair of iterators representing the range of elements with the specified key in the multimap.
The below program demonstrates how we can find all occurrences of a specific key in a multimap in C++ STL.
Occurrences of the key 'student' are: John Bob Alice Mike
Time Complexity: O(log N), where N is the size of the multiset.
Auxiliary Space: O(1)