Count occurrences with Dictionary<string,int>.
Ready — edit the code above and click Run.
using System;
class Program
{
static void Main()
{
using System.Collections.Generic;
var freq = new Dictionary<string, int> { ["a"] = 2, ["b"] = 1 };
Console.WriteLine(freq["a"]);
}
}
Try solving on your own first, then reveal the official answer.
Dictionary gives O(1) average lookup—hash map interviews.