Search This Blog

Monday, September 29, 2025

firstnonrepeatingcharacter

 public void firstnonrepeatingcharacter()
{
    // Find First Non-Repeating Character* > In a string "swiss", return the first non-repeating character → "w".
    string s1 = "swiss";
    var objdict = s1
        .GroupBy(x => x)
        .ToDictionary(x => x.Key, y => y.Count());
    foreach (var item in s1)
    {
        if (objdict[item] == 1)
        {
            Console.WriteLine("First letter is - " + item);
            return;
        }
    }
}

No comments:

Post a Comment