Write a function max_freq that takes in a string and returns maximum frequency of the characters in the string, i.e. the highest number of occurrences of a character.
Hint: You can use a std::map to maintain a count of the characters.
#include <string>
using namespace std;
int max_freq(string str) {
//code
}
1
Expert's answer
2018-04-27T12:07:08-0400
#include <string> #include <map>
int max_freq(std::string str) { std::map<char, int> counts; int maxCount = 0; for (auto ch : str) { auto insertResult = counts.insert(std::pair<char, int>(ch, 1)); if (!insertResult.second) insertResult.first->second++;
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment