How to check if a word is an Isogram? (meaning it doesn’t have repeating letters)

Checking for repeating letters with C#.

Abdallah Yashir
1 min readApr 3, 2023

Here is the exercise on CodeWars.

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. Assume the empty string is an isogram. Ignore letter case.

Example: (Input → Output)

“Dermatoglyphics” → true “aba” → false “moOse” → false (ignore letter case)

isIsogram "Dermatoglyphics" = true
isIsogram "moose" = false
isIsogram "aba" = false

For me, as a reflect, whenever I see the unique keyword in any problem, I immediately think about Sets.

using System;
using System.Collections.Generic;

public class Kata
{
public static bool IsIsogram(string str)
{
var value = str.ToLower();

var set = new HashSet<string>();

foreach(char c in value)
{
set.Add(c.ToString());
}

return set.Count == value.Length ? true : false;
}
}

--

--

Abdallah Yashir
Abdallah Yashir

Written by Abdallah Yashir

Senior Software Developer, Writer, Amateur Photographer, Reader