Codewars Experiment #2: Isograms

Sujith Santhosh Kumar
2 min readJun 22, 2019

--

Q: An isogram is a word that has no repeating letters, consecutive or non-consecutive. Implement a function that determines whether a string that contains only letters is an isogram.
Note: Assume the empty string is an isogram. Ignore letter case.

For this question, here are the given constraints:
-Empty string is considered an isogram.
-The input is not case sensitive.
-Function Input: String
-Function Output: Boolean

I initially approached this question and wrote up a snippet function that did the following:
- Took a string as an input.
- Did a check for empty string and returned 1(or true) if it was.
- Loop over the string and for every character, have a secondary loop to check for duplicates from the next character onward.

I ran the given tests that they had, which was the following:
- isIsogram “Dermatoglyphics” == true
- isIsogram “moose” == false
- isIsogram “aba” == false

And with these tests, I passed and I thought I was done. I tried doing a submission attempt and all of a sudden, there were some errors I had not in the code saying that some Isograms were not detected.

So I went back to the drawing board and tried to figure out what happened and I ran through my examples, one step at a time and spend a while trying to figure out what was in front of me.
The problem was that the examples I had didn’t account for all cases, and the one that I was missing was the case-sensitivity issue. Despite logic saying “A”
and “a” are the same, in ASCII, they are totally different.

Once this was identified, I reworked my code to convert the entire string to lowercase since case was not important and ran the final submission and it passed the random tests as well.

Here’s my final code(code is in C++11):

My take away: One of the key things in any coding challenge is to identify the constraints of the problem and have examples with all potential cases.

--

--

Sujith Santhosh Kumar

Just another soul looking into the inner workings of life and logic.