u can try this
class Program
{
static void Main()
{
string string1 = "ABCDEFGH";
string string2 = "ABCDFGK";
bool result = CheckStrings(string1, string2);
Console.WriteLine(result ? "Strings match the criteria" : "Strings do not match the criteria");
}
static bool CheckStrings(string s1, string s2)
{
// Define vowels and consonants
char[] vowels = { 'A', 'E', 'I', 'O', 'U' };
char[] consonants = "BCDFGHJKLMNPQRSTVWXYZ".ToCharArray();
// Check length difference
if (Math.Abs(s1.Length - s2.Length) != 1)
{
return false; // One should be one letter longer due to the missing vowel
}
// Count consonant differences
int consonantDifferences = 0;
for (int i = 0, j = 0; i < s1.Length && j < s2.Length; i++, j++)
{
if (s1[i] != s2[j])
{
if (consonants.Contains(s1[i]) && consonants.Contains(s2[j]))
{
consonantDifferences++;
if (consonantDifferences > 1)
{
return false;
}
}
else if (vowels.Contains(s1[i]))
{
j--; // s2 is missing a vowel, so decrement j to re-check this position
}
else if (vowels.Contains(s2[j]))
{
i--; // s1 is missing a vowel, so decrement i to re-check this position
}
else
{
return false; // Characters don't match and it's not a vowel
}
}
}
// Ensure one consonant difference and one missing vowel
return consonantDifferences == 1 && (s1.Length > s2.Length ? CountVowels(s1) - CountVowels(s2) == 1 : CountVowels(s2) - CountVowels(s1) == 1);
}
static int CountVowels(string s)
{
char[] vowels = { 'A', 'E', 'I', 'O', 'U' };
return s.Count(c => vowels.Contains(c));
}
}