this is error that is coming
terminate called after throwing an instance of 'std::length_error' what(): basic_string::_M_replace_aux
this is the code i wrote
`class Solution {
public:
string frequencySort(string s) {
priority_queue<pair<int, char>> pq;
unordered_map<char, int> hm;
for (char c : s) {
hm[c]++;
}
for (const auto& entry : hm) {
pq.push(make_pair(entry.second, entry.first));
}
string result = "";
while (!pq.empty()) {
pair<char, int> p = pq.top();
pq.pop();
result.append(p.first, p.second);
}
return result;
}
};`
I would just like to know what that error means so I know how to fix it. I’ve seen many posts with similar errors but nothing exactly the same. I am literally just starting out in C++, and none of those answers make sense with what I have learned so far. As you can see this is a simple program to output a song. It’s meant to help me practice strings for the class I’m taking, but it makes absolutely no sense to me and the book isn’t much help either. Could someone please explain this to me?
that platform i used is leetcoded,this my ans for the “question sort characters by frequency” que no 451
rahul Uchiha is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.