![]() |
VOOZH | about |
In C++, Multimap is similar to a map that stores the data in the key-value format but the difference between these two containers is that we can have multiple elements with the same keys. In this article, we will learn how to find the frequency of a specific key in a multimap in C++.
Example
Input:
multi_map = {{10,"A"},{10,"B"},{10,"C"},{5,"A"},{10,"D"},{4,"C"}}
Key = 10
Output:
Frequency of Key 10 is 4
The std:::multimap::count function in C++ STL is used to find the total number of key occurrences present in the multimap. It takes the key as a parameter and returns the integer that represents the total occurrences.
The below example demonstrates how we can use the std::count function to find the frequency of a specific key in a multimap in C++ STL.
Frequency of Key 10 is 4
Time complexity: O(logN)
Auxilliary Space: O(1)