O(n) using small map

Here’s what I did, small memory requirement and very fast.

/**
 * Check if a guess is an isogram (i.e. all letters are different).
 */
bool FBullCowGame::IsIsogram(FString Guess) const
{
    std::map<char, bool> CharFound;
    for (int32 i = 0; i < Guess.length(); i++)
    {
        char Ch = Guess[i];
        if (CharFound[Ch])
        {
            return false;
        }
        CharFound[Ch] = true;
    }
    return true;
}

Privacy & Terms