using System.Collections.Generic;
public static void Main(string[] args)
Console.WriteLine("Do All Test Cases Pass?: {0}", TestUniquePatternCount());
static Dictionary<String, int> UniquePatternCount(String str, int patternLength)
Dictionary<String, int> uniquePattern = new Dictionary<string, int>();
if (patternLength <= 0 || str == "")
for(int i = 0; i<str.Length - patternLength; i++)
String sub = str.Substring(i, patternLength);
if (uniquePattern.ContainsKey(sub))
uniquePattern.Add(sub, 1);
uniquePattern = uniquePattern.Where(kvp => kvp.Value>1)
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
static bool TestUniquePatternCount()
Dictionary<String, int> res = UniquePatternCount("", 0);
res = UniquePatternCount("", 2);
res = UniquePatternCount("abcd", 0);
res = UniquePatternCount("zf3kabxcde224lkzf3mabxc51+crsdtzf3nab=", 3);
if(!res.ContainsKey("zf3") || !res.ContainsKey("bxc") || !res.ContainsKey("abx") || res["zf3"] != 3 || res["bxc"] != 2 || res["abx"] != 2)