Mid From PDF MNC Coding C# MNC Coding Interview

First non-repeating character in a string?

Logic

  • Count character frequency.
  • Traverse string again to find the first with count = 1.
string input = "swiss";
Dictionary<char, int> map = new Dictionary<char, int>();
foreach (char c in input)
map[c] = map.ContainsKey(c) ? map[c] + 1 : 1;
foreach (char c in input)
{
if (map[c] == 1)
{

Console.WriteLine(c);

break;

}
}

More from C# Programming Tutorial

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details