Made my IsIsogram function using an array containing a number for each letter in the alphabet that I use to track the sum of each letter in a word, then just check if the max element of the array is > 1.
Meaning I only need to loop through the word once.
bool UBullCowCartridge::IsIsogram(const FString Word)
{
// Initialise alphabet array
// a b c d e f g h i j k l m n o p q r s t u v w x y z
int32 LetterCounts[26] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// Loop through word adding occurences of letter to alphabet array
for (int32 i = 0; i < Word.Len(); i++)
{
char Letter = Word.ToLower()[i];
++LetterCounts[Letter - 'a'];
}
// Check if maximum value in alphabet array if greater than 1
if (*std::max_element(LetterCounts, LetterCounts + 26) > 1)
{
return false;
}
return true;
}
Edit:
Iām aware this will fail if something other than a plain letter is passed to the function so Iām adding further input validation elsewhere in the program