using System.Collections.Generic;
using System.Collections;
public static void Main()
Console.WriteLine("Hello World");
Console.WriteLine("{0}",FindLogestSubstring("araaci",1));
public static int FindLogestSubstring(string inputStr, int numDistinctChar) {
char[] chrArr = inputStr.ToCharArray();
Hashtable ht = new Hashtable();
int maxSubStringLength = 0;
for ( int windowEND = 0; windowEND < chrArr.GetLength(0); windowEND++) {
if (!ht.ContainsKey(chrArr[windowEND]))
ht.Add(chrArr[windowEND],1);
ht[chrArr[windowEND]] = Convert.ToInt32(ht[chrArr[windowEND]]) + 1;
while ( ht.Count > numDistinctChar) {
if (Convert.ToInt32(ht[chrArr[windowSTART]]) == 1)
ht.Remove(chrArr[windowSTART]);
ht[chrArr[windowSTART]] = Convert.ToInt32(ht[chrArr[windowSTART]]) - 1;
maxSubStringLength = Math.Max(maxSubStringLength, windowEND- windowSTART +1);
return maxSubStringLength;