Isogram Word

Write a program to verify whether given word is Isogram or not.

An isogram is a word with no repeating letters (such as ambidextrously) or, more broadly, a word in which the letters occur an equal number of times. It is also known as a non-pattern word

Wikipedia

For example

Input:
Good
India

Output:
False
True

Solution:

using System;

namespace Isogram
{
    class Program
    {
        static void Main()
        {
            Console.WriteLine("Enter Word");
            var str = Console.ReadLine();

            Console.WriteLine(IsIsogram(str));
            Console.ReadLine();
        }

        static bool IsIsogram(string str)
        {
            str = str.ToLower();
            var len = str.Length;

            var arr = str.ToCharArray();

            Array.Sort(arr);
            for (var i = 0; i < len - 1; i++)
            {
                if (arr[i] == arr[i + 1])
                    return false;
            }
            return true;
        }

    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *