Mid From PDF Coding C# Coding Interview

Count Number of Occurrences of Each Character in a?

String
Dictionary<char, int> CountCharacters(string s)
{
var dict = new Dictionary<char, int>();
foreach (char c in s)
{
if (dict.ContainsKey(c))

dict[c]++;

else

dict[c] = 1;
}
return dict;
}

Explanation:

Simple frequency map using Dictionary.

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