public static void Main()
string word1 = "abc11223cabbbb321";
countDuplicateChar(word1);
string word2 = "abc11223cabbbb321ddfffeee";
countDuplicateChar(word2);
static void countDuplicateChar(string word)
char[]S = word.ToCharArray();
for (int i = 1; i < n; i++)
lastChar = lastChar ?? S[j];
if (S[j] == S[i] && lastChar != S[i])
char[] A = new char[j + 1];
Array.Copy(S, 0, A, 0, j + 1);
string response = string.Format("Duplicates in {0} = {1}", word, duplicate);
Console.WriteLine(response);