Vote for Big O notation

When looking at the problem, your most efficient method can get you down to O(n). This can be achieved by using std::map containing the letters and boolean (all false at first). You loop through the word letter by letter and and in the map update the boolean to true for each letter. If the boolean is already true, then you have hit a duplicate and return that it is not an isogram.

It’s important to think about speed, but also take scope into consideration. This is a small program where the maximum word length would be around 15 (or potentially 26 if someone typed out all the letters of the alphabet because we are not checking if the entry is actually a word). O(n log n) or O(n^2) could be acceptable for the scope of this game, but just keep in mind that if you were to continue to add to this game, those times would slowly add up.

1 Like

Privacy & Terms