Untitled

 avatar
unknown
c_cpp
a year ago
771 B
6
Indexable
vector<vector<string>> getStringAnagramWithHighestCount(vector<string> strs) {
    unordered_map<string, vector<string>> anagramGroups;
    int maxCount = 0;

    // Group anagrams based on sorted strings
    for (const string& str : strs) {
        string sortedStr = str;
        sort(sortedStr.begin(), sortedStr.end());
        anagramGroups[sortedStr].push_back(str);
        maxCount = max(maxCount, static_cast<int>(anagramGroups[sortedStr].size()));
    }

    // Collect anagram groups with highest count
    vector<vector<string>> result;
    for (auto it = anagramGroups.begin(); it != anagramGroups.end(); ++it) {
        if (it->second.size() == maxCount) {
            result.push_back(it->second);
        }
    }

    return result;
}
Editor is loading...
Leave a Comment