using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.IO; using System.Xml; using System.Text.RegularExpressions; public interface ICodeRush { int? FindLeastFrequentNumber(IList list); } public class Solution : ICodeRush { public int? FindLeastFrequentNumber(IList list) { if (list == null || list.Count == 0) { return null; } var lookup = new Dictionary(); var array = list.ToArray(); int length = array.Length; int count = 0; while (count < length) { bool exists = lookup.ContainsKey(array[count]); switch (exists) { case true: lookup[array[count]]++; break; default: lookup.Add(array[count], 1); break; } count++; } int lowest = int.MaxValue; int key = 0; var lookupArray = lookup.ToArray(); int lookupLength = lookupArray.Length; int currentLookupIndex = 0; while (currentLookupIndex < lookupLength) { bool lower = lookupArray[currentLookupIndex].Value < lowest; switch(lower) { case true: lowest = lookupArray[currentLookupIndex].Value; key = lookupArray[currentLookupIndex].Key; break; default: break; } currentLookupIndex++; } return key; } }