write a function to print the frequency of characters eg. Input : aabbbc Output: a2b3c1
Sigiloso
Complexity is O(n) class CharsFrequency { public static Hashtable CharacterFrequency(string strInput) { Hashtable ht = new Hashtable(); foreach (char item in strInput) { if (ht.ContainsKey(item)) { ht[item] = Int32.Parse(ht[item].ToString()) + 1; } else { ht[item] = 1; } } return ht; } }