Search This Blog

Monday, September 29, 2025

uniqueCharacters

//*10.Check if a String Has All Unique Characters * > "abcdef" → true, "apple" → false.
string s1 = "apple";
var d1 = s1
    .GroupBy(x => x)
    .ToDictionary(x => x.Key, y => y.Count());
foreach (var item in d1)
{
    if(item.Value > 1)
    {
        Console.WriteLine("Repeating character - " + item.Key);
        return;
    }
}

No comments:

Post a Comment