Vote for O(n)

If we include validation to ensure that the guess is alphabetic, then there are only 26 possible letters…
So how about we have an array - of 26 Boolean occurrences initialised as false.
Then for each letter, check the appropriate occurrence for that letter (eg. A = 0, C=1, Z=25 etc.). If it is false, set it to true (ie we are marking that we have that letter in the word). If is already true, then we have already used that letter - and it is therefore not an Isogram,

Only a single pass needed.

(ofc. I don’t know how to do arrays, nor check for alphabetic in C++ yet…)

Thoughts?

Oh…

I’ve just listened to the answer in the lecture…

This argument makes sense to me, where the introduction to the challenge didn’t. Thank you for your suggestion, Brian.

Privacy & Terms