using System;
class Program
{
/// <summary>
/// Finds the length of the shortest common supersequence.
/// </summary>
/// <param name="s1">First string.</param>
/// <param name="s2">Second string.</param>
/// <param name="i1">Starting index of substring.</param>
/// <param name="i2">Ending index of substring.</param>
/// <returns>Length of shortest common supersequence.</returns>
static int ShortestCommonSupersequenceRecursive(string s1, string s2, int i1, int i2)
{
if (i1 == s1.Length)
return s2.Length - i2;
if (i2 == s2.Length)
return s1.Length - i1;
if (s1[i1] == s2[i2])
return 1 + ShortestCommonSupersequenceRecursive(s1, s2, i1 + 1, i2 + 1);
int length1 = 1 + ShortestCommonSupersequenceRecursive(s1, s2, i1, i2 + 1);
int length2 = 1 + ShortestCommonSupersequenceRecursive(s1, s2, i1 + 1, i2);
return Math.Min(length1, length2);
}
/// <summary>
/// Finds the length of the shortest common supersequence.
/// </summary>
/// <param name="s1">First string.</param>
/// <param name="s2">Second string.</param>
/// <returns>Length of shortest common supersequence.</returns>
public static int ShortestCommonSupersequence(string s1, string s2)
{
return ShortestCommonSupersequenceRecursive(s1, s2, 0, 0);
}
// Driver code to test the above method
public static void Main()
{
Console.WriteLine(ShortestCommonSupersequence("abcdz", "bdcf"));
Console.WriteLine(ShortestCommonSupersequence("educative", "educative.io"));
}
}